NSToolbar 和视图控制器层次结构
我有以下类层次结构:
NSViewController
MyGeneralViewController
ViewControllerA
ViewControllerB
MyGeneralViewController
包含 ViewControllerA
和 ViewControllerB
使用的一些通用代码。一段常见代码是创建 NSToolbar
并为 NSToolbarDelegate
实现必要的协议方法。
工具栏中的按钮之一是允许用户在单独的窗口中打开 NSTextView 的按钮(更多空间、用于处理关键字的附加功能等)。
其方法是:
- (IBAction) openTextWindow: (id) sender {
[self setTextWindowController: [[TextWindowController alloc] init]];
[[self textWindowController] showWindow];
}
此工具栏按钮应该仅对 ViewControllerA
控制的视图可用。我的推理是,如果我仅为 ViewControllerA
实现 openTextWindow
方法,则对于由 ViewControllerB
控制的视图,工具栏按钮将显示为灰色(不可用) >,因为运行时系统会沿着类层次结构向上查找为工具栏按钮定义的方法,但找不到它。
事实似乎并非如此。当我使用 MyGeneralViewController 实现该方法时,该按钮始终可用(如预期但不是我想要的)。但是当我仅为 ViewControllerA
实现它时,它永远不可用。
我错过了什么还是这就是它应该工作的方式?
I have the following class hierarchy:
NSViewController
MyGeneralViewController
ViewControllerA
ViewControllerB
MyGeneralViewController
holds some common code used by both ViewControllerA
and ViewControllerB
. One piece of common code is the creation of an NSToolbar
and the implementation of the necessary protocol methods for NSToolbarDelegate
.
One of the buttons in the toolbar is a button that allows the user to open a NSTextView
into a separate window (more real estate, additional functionality for working with keywords etc).
The method for this is:
- (IBAction) openTextWindow: (id) sender {
[self setTextWindowController: [[TextWindowController alloc] init]];
[[self textWindowController] showWindow];
}
This toolbar button should only be available for the view controlled by ViewControllerA
. My reasoning was that if I implement the openTextWindow
method only for ViewControllerA
, the toolbar button would be greyed (not available) for the view controlled by ViewControllerB
, as the runtime system would go up the class hierarchy to look up the method that was defined for the toolbarbutton and not find it.
This appears to be not the case. When I implement the method with MyGeneralViewController
, the button is always available (as expected but not what I want). But when I implement it only for ViewControllerA
it's never available.
Am I missing something or is this the way it is supposed to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
诡异的。离开了一段时间后,我决定再试一次。对项目进行清理后,一切都按预期进行。
Weird. After leaving this for a while, I decided to give it another go. Following a clean of the project it all worked as expected.