为各种 NSWindowController 启用/禁用打印菜单项
我已经更改了“打印”菜单项以将 -printWindow: 消息发送到第一响应者,并在我的两个窗口控制器(我的主窗口和辅助窗口)上定义了该方法。在我的主窗口上,一切正常。但是,当我关注第二个窗口时,“打印”菜单项将自动禁用。
@interface SecondaryWindowController : NSWindowController {
}
- (IBAction) printWindow:(id)sender;
我的实现:
- (IBAction) printWindow:(id)sender {
NSLog(@"called print:%@", sender);
}
如果我理解菜单项的自动验证,它应该爬上第一响应者层次结构,寻找响应所选选择器的对象......这应该是我的SecondaryWindowController,但菜单项被禁用。知道我做错了什么吗?
I have changed my Print menu item to send the -printWindow: message to First Responder and defined that method on two of my window controllers (my primary and a secondary window). On my primary window, everything works fine. However, when I focus on the second window the Print menu item is being automatically disabled.
@interface SecondaryWindowController : NSWindowController {
}
- (IBAction) printWindow:(id)sender;
My implementation:
- (IBAction) printWindow:(id)sender {
NSLog(@"called print:%@", sender);
}
If I understand auto validation of menu items, it should climb up the first responder hierarchy looking for an object that responds to the chosen selector... which should be my SecondaryWindowController, but the menu item is disabled. Any idea what I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,我需要将窗口的委托出口连接到文件所有者(我的窗口控制器)。然后菜单能够正确自动验证并启用菜单项。
It turned out that I needed to connect the delegate outlet of the window to File's Owner (my Window Controller). Then the menus were able to autovalidate properly and the menu item is enabled.