NSView 自定义上下文菜单和按键
我的应用程序主窗口中有一个 NSCollectionView ,它管理自定义 NSView 项目的集合。每个自定义视图都有一个分配给它的上下文菜单。我想为某些项目添加快捷键,例如将“删除”键与“从集合中删除项目”操作相关联。我已经通过 IB 添加了与上下文菜单项等效的键,但问题是如何使集合项响应按下的键?
我知道我可以通过将此菜单添加到 NSApp 的主菜单并跟踪所选项目来实现此目的。除此之外还有其他办法吗?
i have an NSCollectionView in my application's main window that manages a collection of custom NSView items. Each custom view has a context menu assigned to it. I want to add shortcut keys to some of the items, for example to associate a "delete" key with "remove item from collection" action. I've added key equivalents to context menu items through IB but the question is how do i make the collection items respond to the pressed keys?
I know that i can achieve this by adding this menu to the NSApp's main menu and keep track of the selected item. Is there any other way besides that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将类似的内容添加到您的 NSCollectionView 子类中:
You could add something like this to your NSCollectionView subclass: