可可:NextKeyView-Tab顺序 [英] Cocoa: NextKeyView - Tab Order

查看:58
本文介绍了可可:NextKeyView-Tab顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的可可应用程序中,我想更改控件的制表符顺序,以便可以从文本字段切换到按钮。我确实用按钮连接了文本字段的nextKeyView属性,但它似乎根本没有任何作用。



我已经为键盘激活了适当的系统设置,因此可以使用Tab键现在所有控件。

解决方案

@sach提供的答案为我解决了这个问题。 / p>

我创建了一个新的故事板项目,并添加了3个文本字段。我通过将它们与Interface Builder中的nextKeyView链接在一起来设置自定义顺序,但这在运行时没有任何效果。这是我可以用来复制您(和我的)问题的最简单的测试用例。



要使用@sach的答案来解决它,请创建一个新的插座并连接到 NSTextField s之一:

  @IBOutlet var firstTextField: NSTextField! 

然后在ViewController中,我添加了:

 重写func viewWillAppear(){
//必须在连接窗口后执行此操作
self.view.window!.initialFirstResponder = nameField
}

重新运行,文本字段根据使用nextKeyView链接设置的顺序正确循环


in my cocoa application I want to change the tab order of the controls so I can switch from a textfield to a button. I did connect the nextKeyView property of the textfield with the button but it seems to have no effect at all.

I already activated the appropriate system settings for Keyboard so I can tab to all controls now. It works fine but not in the order I set as nextKeyView.

解决方案

The answer provided by @sach solved this for me.

I created a new storyboard project, and added 3 text fields. I set a custom order by linking them together with nextKeyView in Interface Builder, but this had no effect at runtime. This is the simplest test case that I could come up with to replicate your (and my) problem.

To solve it using @sach's answer, create a new outlet and connect it to one of the NSTextFields:

@IBOutlet var firstTextField: NSTextField!

In the ViewController, I then added:

override func viewWillAppear() {
    // Must execute this after the window is connected
    self.view.window!.initialFirstResponder = nameField
}

Re-run and the text fields cycle properly according to the order set using the nextKeyView links

这篇关于可可:NextKeyView-Tab顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆