不起作用:NSToolbarItem +自定义视图 +设置动作:
我以编程方式在继承 NSObject
的界面内添加一个工具栏,并实现这些方法:
- (NSToolbarItem*)toolbar:(NSToolbar*)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)willBeInsertedIntoToolbar;
- (NSArray *)toolbarSelectableItemIdentifiers: (NSToolbar*)toolbar
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
我还通过在 NSToolbarItem 上调用 setView
来添加一个按钮。该视图包含一个 NSButton 并且位于 .XIB 接口中。
但是,由于 http://www.cocoabuilder.com/archive/cocoa/291782-nstoolbaritem-custom-view-setaction.html#291783。
我该如何实施这个解决方案?
I'm adding a toolbar programmatically inside an interface inheriting NSObject <NSToolbarDelegate>
, and implementing these methods:
- (NSToolbarItem*)toolbar:(NSToolbar*)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)willBeInsertedIntoToolbar;
- (NSArray *)toolbarSelectableItemIdentifiers: (NSToolbar*)toolbar
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
I also add a button by calling setView
on a NSToolbarItem. This view contains an NSButton and is in the .XIB interface.
However, setAction
on the same item does not work, due to reason described at http://www.cocoabuilder.com/archive/cocoa/291782-nstoolbaritem-custom-view-setaction.html#291783.
How do I implement this solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在 nib 文件本身中设置
NSButton
的目标和操作,或者如果您需要以编程方式执行此操作,则为NSButton< 创建一个
IBOutlet
/code> 并在代码中执行。当您在工具栏项中使用
NSButton
时,它实际上就像界面中其他任何地方的NSButton
一样,而不是作为每个NSToolbarItem
东南。例如,您将无法通过使用标准-validateToolbarItem:
或-validateUserInterfaceItem:
轻松禁用或启用该按钮;相反,您需要有一个指向相关按钮的IBOutlet
,或者使用绑定来启用或禁用该按钮。You could set the target and action of the
NSButton
in the nib file itself, or if you need to do it programmatically, then create anIBOutlet
to theNSButton
and do it in code.When you use an
NSButton
in a toolbar item, it effectively acts like anNSButton
would anywhere else in your interface, rather than as anNSToolbarItem
per se. For example, you won't be able to easily disable or enable the button through the use of the standard-validateToolbarItem:
or-validateUserInterfaceItem:
; rather, you'll need to have anIBOutlet
to the button in question, or otherwise use bindings to enable or disable the button.