2014-02-27 25 views
0

我遇到的問題非常類似於此threadNSMenuItem在打開窗口後無法選擇

我正在編程創建一個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]; 
} 

我猜我需要以某種方式在窗口的關閉將焦點回到菜單,但我不能爲我的生活弄清楚如何。

回答

1

聽起來好像你還沒有停止模態循環。正如runModalForWindow:的文檔所述,「您可以通過調用模態窗口代碼中的stopModal,stopModalWithCode:abortModal方法退出模態循環。」