简体   繁体   English

Cocoa:如何防止工具栏中的NSSearchField获得第一响应者?

[英]Cocoa: How to prevent NSSearchField in a toolbar to get first responder?

When having a NSSearchField in a toolbar, it automatically becomes first responder when pressing TAB key in the window. 在工具栏中有一个NSSearchField时,它会在窗口中按TAB键时自动成为第一响应者。 How can I prevent that? 我怎么能防止这种情况? Ie to get the search field to refuse first responder? 即让搜索字段拒绝第一响应者?

If using Xcode 4.3.2, open up the XIB file, click the toolbar item twice to select the NSSearchField (one click selects NSToolbarItem). 如果使用Xcode 4.3.2,打开XIB文件,单击两次工具栏项以选择NSSearchField(单击选择NSToolbarItem)。 In the Attributes inspector, tick the "Refuses First Responder" checkbox and Bob's your uncle. 在“属性”检查器中,勾选“拒绝第一响应者”复选框,然后勾选“你的叔叔”。

The trick here is that NSToolbarItem cannot refuse the first responder in general. 这里的诀窍是NSToolbarItem通常不能拒绝第一个响应者。 However, the NSSearchField (whose ancestor is the NSToolbarItem) can refuse. 但是,NSSearchField(其祖先是NSToolbarItem)可以拒绝。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM