Is your NSTableView showing 2 tooltips?

Is your NSTableView or NSOutlineView showing 2 tooltips (in Mac OS X 10.5 or later)?

If so, you may be being bit by some well-meaning automagical code. But there’s a simple solution. Read on!

Tooltips are good things, especially in places like tables where the columns and cells may be too small to show the complete contents. Apple realizes this and chose to automagically display a tooltip with the full cell contents could not be displayed. This was added in Leopard but it’s not actually a tooltip! It’s a special thing called an “expansion frame“.

If you do nothing, your app automagically gains this functionality. It’s quite nice, and generally speaking a good thing.

If however your NSTableView or NSOutlineView already provides its own tooltips (e.g. you implement -[NSTableView tableView:toolTipForCell:rect:tableColumn:row:mouseLocation:] or -[NSOutlineView outlienView:toolTipForCell:rect:tableColumn:item:mouseLocation]), now you could wind up with two tooltips… or rather, your tooltip and the automagical “expansion frame”. It’s not the right user experience.

The solution?

NSCell has a method, -expansionFrameWithFrame:inView:. That’s what provides the magic. All you have to do is override it in your NSCell subclass and return NSZeroRect. That’s it. Suppression made simple, with just a little bit of subclassing. And don’t forget… you don’t need to change this in code. If your code never explicitly installs datacells into the table, then you’re using the default NSTextFieldCell‘s already in the tableview within the nib. So just change the NSTextFieldCell instances within the nib. Simple and easy.