将工具栏与多个 NSViewController 一起使用
我有一个基于文档的单窗口应用程序,它加载多个用作主视图的 NSViewController。每个视图控制器都是一个独立的类,用于处理某些业务需求,并因此实现工作所需的所有方法。
我的问题是如何在加载特定视图控制器时使工具栏工作。只要它们在窗口类中实现,我就可以将工具栏连接到委托并将工具栏项目连接到操作。但是,如果我尝试在视图的 loadView 方法上为工具栏项设置新操作,则工具栏项会忽略它并继续调用主窗口类上的方法。
那么,如何动态更改工具栏项上的操作呢?
I've a single window Document-based application that loads several NSViewControllers that serve as the main view. Each view controller is a self-contained class that deals with certain business needs and as such implements all methods necessary to work.
My problem is how to make the toolbar work when a specific view controller is loaded. I've no problems wiring the toolbar to a delegate and the toolbar items to actions as long as these are implemented in the window class. But if I try to set a new action for a toolbar item on the loadView
method of a view, the toolbar item simply ignores it and continues calling the method on the main window class.
So, how can I dynamically change the action on a toolbar item?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你也设定目标了吗? (即
[foo setTarget:]
除了[foo setAction:]
)大概你的窗口控制器有某种
currentViewController
ivar/property?切换视图控制器时最好不要重新分配工具栏操作,而是使用窗口控制器将它们传递到当前活动的视图控制器上。Are you setting the target as well? (ie
[foo setTarget:]
in addition to[foo setAction:]
)Presumably your window controller has some sort of
currentViewController
ivar/property? It might be better not to reassign the toolbar actions when switching view controllers, and instead use the window controller to pass them on the currently active view controller.