Hi,
I wonder what’s the correct way to invoke a tool tip for a table column (not a cell).
I tried to assign a tool tip to NSTextFieldCell in Interface Builder, but it didn’t work.
Then I found this method of NSTableView:
- (NSString *)tableView:(NSTableView *)tv toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tc row:(int)row mouseLocation:(NSPoint)mouseLocation
.and after reading various sources and finding some examples, managed to successfully create a class ToolTipController, and set it as the delegate for my table view. (I’m actually proud that it’s the first time I was able to properly create and connect a controller class). Now the table view properly displays a tool tip with the content of the cell if the text in the cell is longer than the column width:
#import “ToolTipController.h”
@implementation ToolTipController
- (NSString *)tableView:(NSTableView *)tv toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tc row:(int)row mouseLocation:(NSPoint)mouseLocation {
if ([cell isKindOfClass:[NSTextFieldCell class]]) {
if ([[cell attributedStringValue] size].width > rect->size.width) {
return [cell stringValue];
}
}
return nil;
}
@end
BUT, that’s NOT what I need. I want the tool tip to explain the meaning of the data in the column (i.g. “File name” for a column with identifier “name”, “Image color mode” for a column “mode” etc.)
I tried to insert
if ([cell isKindOfClass:[NSTableHeaderCell class]])
hoping that it’ll make the tool tip to appear when the mouse is over the column header, but it didn’t work.
I also tried this:
- (NSString *)tableView:(NSTableView *)tv toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tc row:(int)row mouseLocation:(NSPoint)mouseLocation {
NSString *idColumn, * testString;
testString=@“File name”;
if ([cell isKindOfClass:[NSTextFieldCell class]]) {
idColumn=[tc identifier];
if (idColumn == @"name"]) {
return testString;
}
}
return nil;
}
.but it didn’t work either. My understanding is that I’m not coercing the values properly:
The method for getting column’s identifier - [tc identifier] - returns id and not string. So basically I need to know how to coerce the column identifier into string, and my knowledge of Obj-C is still not good enough for this.
Hope it all makes sense.
Thanks for any help,
Leo