如何使用 NSButton 中的方法扩展 NSButtonCell?

How do I extend NSButtonCell with a method in NSButton?

我不熟悉子类化或扩展 Cocoa 框架。
NSButton 有一个 setToolTip 方法,但是 NSButtonCell 没有。我不想添加新的 IBOutlets,那么如何通过访问 NSButton 的方法来完成此操作?

我有一系列复选框,所有复选框都带有 NSButtonCell 插座。我无法访问 setToolTip 方法,但如果我要在同一件事上制作 NSButton 插座,我确实会被卡住。

/* Tooltips require you to connect the NSButton not NSButtonCell */
   [myButton setToolTip:@"This does xyz"];

本例中的工具提示来自 NSViewNSButton 继承自 NSView,但您需要稍微避开 NSButtonCell,例如使用其 controlView 属性 来获取单元格的视图:

[myButtonCell.controlView setToolTip:@"tool tip"];