NSImageCell: Set ToolTip - objective-c

I'm trying to show a tooltip on the mouse hover at a NSImageCell. I've tried setting the property on Interface Builder (both on the NSImageCell and the NSTableColumn that contains it) but it didn't work.
Any ideas?

Neither NSCell nor NSTableColumn will display tool tips, because neither is a subclass of NSView. You will have to set the tool tip on the table view itself.
You can use -[NSView addToolTipRect:owner:userData:] to set a tool tip for a particular area of a view. In combination with -[NSTableView frameOfCellAtColumn:row:], you ought to be able to set up a different one for each cell.

I solved this by overriding this method in the controller for my NSOutlineView:
- (NSString *)outlineView:(NSOutlineView *)outlineView toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tableColumn item:(id)item mouseLocation:(NSPoint)mouseLocation;

In case of NSTableView you can use
(NSString *)tableView:(NSTableView *)tableView toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row mouseLocation:(NSPoint)mouseLocation;

Related

How to bring the custom view cell above table rows in NSTableView?

When I use a custom view as the cell of a view-based NSTableView, the custom view is somewhat below the table row. When I click on it, instead of affecting the elements (e.g. text field) custom view, the table row was selected (and highlighted). I have to reclick to select the text field.
- (NSView*)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
NSLog(#"We are creating views!");
NSTableCellView *newView;
newView = [tableView makeViewWithIdentifier:#"PostCell" owner:self];
NSTextField *newTextField = [[NSTextField alloc] init];
[newView addSubview:newTextField];
return newView;
}
When I disable the row selection according to NSTableView - Disable Row Selection, there was no selection.
- (BOOL)selectionShouldChangeInTableView:(NSTableView *)tableView {
return NO;
}
But I still cannot select directly the text field. What's worse, I cannot even select it using the mouse. Only tab on the keyboard works.
There seem to be something above it. But is it the "table column" shown in interface builder? Or something else?
How can I fix this?
Use a custom subclass of NSTableView and override -validateProposedFirstResponder:forEvent: to return YES.
See this blog entry from the Apple engineer who wrote the view-based table view code.
Make sure following code is present.
- (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(NSInteger)rowIndex {
return YES;
}
You may try logging the subviews Or you can check superviews of view.
This will help to understand view hierarchy.
Also on side note if one of the view's userInteraction is disable then it's subview's won't be able to receive the events. Please verify that all the views and it's subviews userInteraction is enable.
I hope this helps.

View-based NSOutlineView and displaying Header Cells

I have been trying unsuccessfully to use so-called "Header Cells" in my view-based (which I'd like to keep that way) NSOutlineView without success.
I have tried the following things:
I have successfully set up -(BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item for the object I want to make headers.
I have thoroughly tested my delegate and data-source, so we can assume they are set up properly.
When it comes to -(NSView *)outlineView:(NSOutlineView *)ov viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item definition, I am stuck.
I had the feeling from my readings that there are things to set up in IB, but I can't figure out what. What is this #"HeaderCell" referring to?
I tried this kind of stuff which are not successful at all (displays an empty-view)
-(NSView *)outlineView:(NSOutlineView *)ov viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item
{ NSTableCellView *result = nil;
result = [ov makeViewWithIdentifier:#"HeaderCell" owner:self];
[[result textField]setStringValue:#"myString"];
return result;
}
What am I missing ?
Source : View-based NSOutlineView header cell font issues
The #"HeaderCell" refers to the Table Cell View identifier. In IB select the Table Cell View representing the Header Cell and on the utility sidebar select identity inspector...you should see the identifier field.
NB : From Cory's Answer
Here's a graphical explanation of how to set it up in Interface Builder :
In IB select the Table Cell View representing the Header Cell and on the utility sidebar select identity inspector...you should see the identifier field

Hide button in NSTableView

I am a little stuck and can't seem to work this out from the apple docs.
I have two buttons in an NSTable column, contained within an NSTableCellView.
I am trying to, in code, hide the button depending on the values of the object in the row.
Getting the values is fine, but i can't work out how to target the specific button, i can't bind it to an outlet as it's within a table. I have tried the below code, but that just hides the entire NSTableCellView rather than the specific button, i have also tried changing the identifier to be of the button, but that seems to do the same.
if(selectedTweet.imageURL){
NSButton *imageButton = [tableView makeViewWithIdentifier:#"secondButtons" owner:self];
[imageButton setHidden:NO];
return imageButton;
} else {
NSButton *imageButton = [tableView makeViewWithIdentifier:#"secondButtons" owner:self];
[imageButton setHidden:YES];
return imageButton;
}
This is obviously much simpler than i am making it?? Help greatly appreciated.
Thanks
Gareth
If you are using CocoaBindings to populate that table, you can just bind the button's "Hidden" attribute to Table Cell View/objectValue.imageURL and use the NSIsNil value transformer. No code needed at all.
If you are using an old-fashioned data source, things become a tad more complicated. In that case you could have a imageButton property in your object, and set it in the NSTableViewDelegate's - (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row method.

Make NSTableView NOT edittable

OK, so here's my situation :
I've got an NSTableView.
Its columns are bound to an NSArrayController.
... which in turn is bound to an NSMutableArray.
However :
When the user click in any of the cells, he's allowed to edit their content.
We DON'T want that.
How should I do it, so that no table cells are editable?
In your NSTableViewDelegate return NO for this method:
- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex

An NSOutlineView with an empty datasource doesn't invoke its delegate methods?

Differently from a NSTableView, the delegate methods of an empty NSOutlineView are never invoked.
For instance, NSTableView method:
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex
is invoked even if there are not rows.
But, NSOutlineView method:
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
is not invoked if there are not items.
I need to write arbitrary text on the first row of my outlineView when it is empty. But I can't use the above mentioned method like I do for NSTableView.
What's the solution ?
thanks
Have you implemented outlineView:numberOfChildrenOfItem: to give a correct answer when passed nil?
From your description it seems to me that it should return 1 (your initial line) when passed nil, but I can't be sure without more code and/or information.