At WWDC, I quickly mentioned how easy it is to add tooltip’s to an NSCell for an NSTableView/NSOutlineView.
Here is a quick snippet of code on how to do this only if the text doesn’t fill up the entire cell:
- (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; }
You will obviously have to set the delegate for the tableview to be whatever class implements the above method, and this will only work on Tiger. But, it is REALLY easy to do.
Next in Apple
I’ve just discovered this method, which would be extremely useful for me. However I can’t seem to get it to function properly (no tooltips are displaying). I’ve set the appropriate delegate – are there any other attributes that need to be set to enable this?
Lou: it should just work…of course, it has to be Tiger or better. Make sure you have the delegate set in addition to the datasource; a common mistake is to forget to set the delegate.
Thanks, it was a delegate issue. The code works as advertised.