2
我的可可应用程序有一个视图,其中显示了大约五十个彩色矩形,它表示一些数据的热图。我无法弄清楚如何将工具提示添加到每个显示矩形代表的数据信息的矩形。我看了看开发者文档,NSView
并添加以下代码:在视图中添加许多工具提示的问题
- (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];
我遇到两个问题:
1)当我打印出的标签的提示,他们都显示1
作为标记,即使它们用于两个不同的矩形。
2)stringForToolTip
方法从未被称为
任何帮助/建议将是伟大的。谢谢!