Tooltips for NSTableView cell’s in Tiger

Apple, Cocoa, General

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.

Previous Post
no_thumbnail
Tiger and the keyboard
Next Post
no_thumbnail
rail unicycle riding at East Cliff Rd, Santa Cruz, CA (aka: 'the hook')

3
Leave a Reply

avatar
500
3 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
corbinLou Recent comment authors
  Subscribe  
Notify of
Lou
Guest
Lou

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
Guest
Lou

Thanks, it was a delegate issue. The code works as advertised.

(c) 2008-2019 Corbin Dunn

Privacy Policy

Subscribe to RSS feeds for entries.

98 queries. 0.245 seconds.

Log in