My Cocoa application has a view with about fifty colored rectangles to be displayed, which represents a heat map of some data. I cannot figure out how to add tool tips to each of the rectangles showing information about the data which that rectangle represents. I looked at the developer documentation for NSView
and have added the following code:
- (NSString *)view:(NSView *)view stringForToolTip:(NSToolTipTag)tag point:(NSPoint)point userData:(void *)data
{
// use the tags to determine which rectangle is under the mouse
if (tag == blueTag) {
return NSLocalizedString(@"The Blue rectangle", @"");
}
if (tag == redTag) {
return NSLocalizedString(@"The Blue rectangle", @"");
}
// we should never get to here!
return NSLocalizedString(@"Unknown tooltip area", @"");
}
// add tooltips for the rectangles (in my drawRect method
// after the rects have been initialized etc.)
[self removeAllToolTips];
redTag = [self addToolTipRect:startingRect owner:self userData:NULL];
blueTag = [self addToolTipRect:blueRect owner:self userData:NULL];
I run into two issues:
1) when I print out the tag for the tooltips, they both show 1
as the tag even though they are for two different rectangles.
2) the stringForToolTip
method is never called
Any help/suggestions would be great. Thanks!