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.


Notify of

Inline Feedbacks
View all comments

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?


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

Subscribe to new posts:

You'll get an email whenever a I publish a new post to my blog and nothing more. -- Corbin

As an Amazon Associate I earn from qualifying purchases.

(c) 2008-2024 Corbin Dunn

Privacy Policy

Subscribe to RSS feeds for entries.

69 queries. 0.156 seconds.

Log in