2011-03-13 89 views

回答

0

我終於明白了。問題是我的基於文檔的應用程序的每個窗口都是無邊界的,最近我讀到無邊界窗口無法通過菜單項(或Cmd-W鍵)發送到firstResponder的performClose:方法關閉。所以我不得不來實現在窗口的子類的一些其他方法:

- (void)performClose:(id)sender { 
    [documentClass canCloseDocumentWithDelegate:self shouldCloseSelector:@selector(document:shouldClose:contextInfo:) contextInfo:NULL]; 
} 

- (void)document:(NSDocument*)doc shouldClose:(BOOL)shouldClose contextInfo:(void*)contextInfo { 
    if (shouldClose) 
     [doc close]; 
} 

- (BOOL)validateMenuItem:(NSMenuItem *)menuItem { 
    return ([menuItem action][email protected](performClose:))?YES:[super validateMenuItem:menuItem]; 
} 

- (BOOL)canBecomeMainWindow { 
    return YES; 
} 

- (BOOL)canBecomeKeyWindow { 
    return YES; 
} 

最後兩個方法確保該窗口可以獲取焦點以及其他一些功能可以執行(像textviews查找命令)。

0

Close菜單項沒有將-performClose:方法發送到「First Responder」對象(最終成爲NSWindow)?我在過去注意到,如果菜單項沒有他們的行爲目標,它們會顯示爲灰色。