开发者

Print Menu Item enabled/disabled for various NSWindowControllers

开发者 https://www.devze.com 2023-04-11 02:55 出处:网络
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

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 focu开发者_JAVA百科s 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号