0
我遇到的問題非常類似於此thread。NSMenuItem在打開窗口後無法選擇
我正在編程創建一個NSMenu並添加我的項目。一個選項顯示一個窗口。這按預期工作。但是,當我關閉窗口時,我不能再選擇菜單中的任何選項。
AppDelegate.m
- (void)createMenu {
NSMenu *statusMenu = [[NSMenu alloc] initWithTitle:@""];
NSMenuItem *historyItem = [[NSMenuItem alloc] initWithTitle:@"History" action:@selector(onHistory:) keyEquivalent:@""];
[statusMenu addItem:historyItem];
NSImage *statusImage = [NSImage imageNamed:@"icon.png"];
[_item setImage:statusImage];
[_item setMenu:statusMenu];
}
- (void)onHistory:(id)sender {
OBHistoryWindowController *historyWindowController = [[OBHistoryWindowController alloc] initWithWindowNibName:@"OBHistoryWindowController"];
historyWindowController.managedContext = self.managedObjectContext;
[historyWindowController showWindow];
}
OBHistoryWindowController.m
- (void)showWindow {
[NSApp runModalForWindow:self.window];
}
我猜我需要以某種方式在窗口的關閉將焦點回到菜單,但我不能爲我的生活弄清楚如何。