我有一个Cocoa应用程序,其中包含一个表格视图和几个其他控件。当应用程序启动并显示窗口时,会在表格视图周围绘制一个蓝色的焦点环。
我该如何去掉焦点环?我希望在窗口首次显示时没有任何控件获得焦点。
我有一个Cocoa应用程序,其中包含一个表格视图和几个其他控件。当应用程序启动并显示窗口时,会在表格视图周围绘制一个蓝色的焦点环。
我该如何去掉焦点环?我希望在窗口首次显示时没有任何控件获得焦点。
该窗口具有initialFirstResponder绑定,显示窗口激活时将处于活动状态的控件。更改initialFirstResponder或在界面构建器中调整tableview设置以隐藏焦点环。
class YourWindowController: NSWindowController {
override func windowDidLoad() {
super.windowDidLoad()
// Wait a frame before setting the first responder to be the window itself.
// We can't just set it right now, because if the first responder is set
// to the window now the system just interprets that as meaning that we
// want the default behavior where it automatically selects a view to be
// the first responder.
DispatchQueue.main.async {
window!.makeFirstResponder(nil)
}
}
}
这很混乱,有时候当窗口加载时,你会看到焦点环在控件的一个框架上开始出现,但我还没有找到更好的方法。