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
方法從未被稱爲
任何幫助/建議將是偉大的。謝謝!