我正在使用Cocoa API爲Mac創建一個簡單的文本編輯器,並且所有工作都正常。唯一的問題是關閉菜單項總是禁用。我應該在文檔控制器中實現一些委託方法嗎?任何已經有這個問題的人?如何在基於Cocoa文檔的應用程序中關閉文檔?
0
A
回答
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)?我在過去注意到,如果菜單項沒有他們的行爲目標,它們會顯示爲灰色。
相關問題
- 1. cocoa基於文檔的應用程序
- 2. 基於文檔的Cocoa應用程序中的文檔類型
- 3. 避免在基於文檔的Cocoa應用程序中耦合?
- 4. 在Cocoa應用程序上禁用基於文檔的功能
- 5. 關於Cocoa應用程序目錄佈局的文檔?
- 6. 單文檔界面基於可可應用程序的文檔
- 7. 在非基於文檔的應用程序中使用核心數據 - Cocoa
- 8. 默認保存在基於Cocoa文檔的應用程序中文檔的位置
- 9. 使用窗口的文檔圖標彈出菜單的基於Cocoa文檔的應用程序中的錯誤
- 10. 如何在基於文檔的應用程序
- 11. 在Swift基於文檔的應用程序中重命名文檔類
- 12. 在基於文檔的應用程序中管理上下文相關的NSMenu
- 13. Domino 6.5 - 關閉框架集文檔 - 關閉應用程序
- 14. 基於文檔的應用程序:哪個是關鍵窗口?
- 15. 如何使用XCTest測試基於文檔的應用程序?
- 16. NSDocumentController如何插入我的基於文檔的應用程序?
- 17. 在基於文檔的mac應用程序中,如何獲取無標題文檔的臨時文件夾?
- 18. 將基本的Cocoa應用程序轉換爲基於文檔的應用程序
- 19. 在基於文檔的應用程序中保存ManagedObjectContext?
- 20. NSUndoManager在基於非文檔的應用程序中
- 21. 無法保存在基於文檔的應用程序中
- 22. 在IPython中關閉文檔
- 23. 具有多種文檔類型的可可基於文檔的應用程序
- 24. 關於在Google Play中啓動應用程序的文檔
- 25. NSDocument *類僅適用於基於文檔的應用程序嗎?
- 26. 基於文檔的應用程序中的不同菜單欄
- 27. 連接基於文檔的應用程序中的菜單項
- 28. 基於文檔的應用程序中的NSNotificationCenter
- 29. 基於文檔的應用程序中的NSUndoManager錯誤行爲
- 30. Cocoa應用程序的文檔相關操作應該在哪裏實施?