找到你要的答案

Q:Is there a method or event when tooltip is going to be displayed?

Q:有一个方法或事件时,工具提示将显示?

I want tooltip to display the coordinates in an NSView. I thought if there was something akin to toolTipWillBeDisplayed that might be called just prior to displaying the tooltip, I could have a method to set the tooltip string to the coordinate the mouse was hovering over. Any ideas or suggestions?

Thanks

我想提示一nsview坐标显示。我想如果有类似tooltipwillbedisplayed可以称为之前显示提示,我可以设置工具提示字符串坐标鼠标悬停在法。有什么想法或建议吗?

谢谢

answer1: 回答1:

There does not appear to be a method/event before a tooltip is displayed.

Any ideas or suggestions?

You can consider replacing the NSView method - (NSToolTipTag)addToolTipRect:owner:userData: using method swizzling. Your replacement method would need to call the original method passing in your own owner and userData with the latter being the original owner & userData. Your owner object would implement - (NSString *) view:stringForToolTip:point:userData: to provide the tooltip by (a) using the original owner & userData to obtain the string and (b) adding the value passed as point.

If you get stuck implementing this ask another question showing what you've written, stating what doesn't work, etc. and someone will probably help you along. If you've never heard of method swizzling you'll find details on it by searching.

HTH

似乎没有一个方法/事件之前,工具提示显示。

有什么想法或建议吗?

你可以考虑更换nsview方法(nstooltiptag)addtooltiprect:老板:用户数据:使用方法调和。你的替换方法就需要调用原方法传递自己的所有者和用户数据与后者的原主人&;用户数据。你的老板会实施对象(NSString *)的观点:stringfortooltip:点:用户提供的提示:(一)使用的原主人&;用户数据获得的字符串和(b)添加传递点的值。

如果你坚持实施这一问题,问另一个问题,显示你写的,说明什么不工作,等等,有人可能会帮助你沿着。如果你从来没有听说过的方法完成了你会通过搜索找到详细信息。

HTH

cocoa  tooltip  nsview