我的應用程序有輸入的NSTextFields;我故意不使用NSNumberFormatter來做特殊的輸入處理。該應用程序實現「全屏」模式。當應用程序處於全屏狀態時,焦點位於文本字段中,然後按Esc鍵恢復窗口模式,而彈出拼寫建議/完成項。當按下ESC鍵時,我不想要這些行爲中的任何一種:完成彈出窗口,也不能退出全屏模式。有什麼建議麼?謝謝。NSTextField中的拼寫建議
0
A
回答
1
您需要設置NSTextFieldDelegate
來處理該命令,並在文本字段上設置委託。這裏有一個例子:
@property (weak) IBOutlet NSWindow *window;
@property (weak) IBOutlet NSTextField *textField;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
self.textField.delegate = self;
}
- (BOOL)control:(NSControl*)control textView:(NSTextView*)textView doCommandBySelector:(SEL)commandSelector {
if (commandSelector == @selector(cancelOperation:)) {
NSLog(@"handleCancel");
return YES;
}
return NO;
}
```
如果你只是想消除拼寫建議,您可以覆蓋下面的方法,但上面並兩者。
- (NSArray *)control:(NSControl *)control textView:(NSTextView *)textView completions:(NSArray *)words forPartialWordRange:(NSRange)charRange indexOfSelectedItem:(NSInteger *)index {
return nil;
}
0
這是我如何實現我想要的行爲:
- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector {
if (commandSelector == @selector(cancelOperation:)) {
if (([_window styleMask] & NSFullScreenWindowMask) == NSFullScreenWindowMask) {
[textView doCommandBySelector:@selector(toggleFullScreen:)];
}
return YES;
}
return NO;
}
相關問題
- 1. uitextview拼寫建議關閉?
- 2. Android中MultiAutoCompleteTextView的拼寫建議?
- 3. 使用Swift在NSTextField中拼寫檢查
- 4. Python的拼寫檢查建議
- 5. 聯合詞的拼寫建議
- 6. Haystack Whoosh拼寫建議太貪婪
- 7. Solr(5.3.1)拼寫檢查vs建議
- 8. 拼寫建議顯示「無」乾草堆
- 9. 處理拼寫檢查建議
- 10. Solr拼寫檢查和建議配置
- 11. JavaScript拼寫檢查器建議
- 12. 拼寫檢查器建議和ArrayIndexOutOfBoundsException
- 13. 如何讓Solr建議者返回拼寫建議以及
- 14. NSTextField自動完成/建議
- 15. 如何獲得marklogic spell中的數字拼寫建議:建議使用api?
- 16. 如何在Mac OS X的NSTextField中啓用拼寫檢查?
- 17. 純Python中的拼寫建議模塊(for GAE)?
- 18. 帶有建議的NSTextField下拉
- 19. 在NSTextField運行時中更改拼寫檢查語言
- 20. 針對Eclipse的Aptana插件進行拼寫檢查的建議
- 21. 針對ASP.NET的多語言拼寫檢查控件的建議
- 22. 如何從solr的synonym.txt獲取拼寫建議?
- 23. 基於多個字段的Solr/Lucene拼寫檢查建議
- 24. 什麼是遍歷Trie檢查拼寫建議的好算法?
- 25. django-haystack:如何訪問模板上的拼寫建議?
- 26. Django-Haystack +飛快移動 - 是否有拼寫錯誤的建議?
- 27. Solr返回差和無效的拼寫建議
- 28. 如何按頻率排序SOLR拼寫檢查建議?
- 29. Solr拼寫檢查/建議和模糊搜索v4.8.1
- 30. Django Haystack - 未設置拼寫建議上下文變量
謝謝您的回答,丹尼爾。我最終使用了你的第一個建議,在做了一些更多的研究以弄清楚如何判斷應用程序處於全屏模式時,我能夠實現我想要的行爲。再次感謝你的幫助。 – wagill