尝试在Xcode for OS X App中设置选项卡顺序 [英] Trying to set the tab order in Xcode for OS X App
问题描述
我正在使用Xcode 7.3构建OS X桌面应用程序,并且试图为其中一种表格设置制表符顺序.
我发现了几篇文章,解释了Xcode 4的类似问题,但没有解决, https://github.com/johnantoni/osx -tab-order
真的欢迎任何想法和指点吗?
一败涂地.
我检查了您的项目,非常好,因为您将其包含在内.它使与AppKit一起玩变得更加容易.我绝不是AppKit的专家,坦率地说,我已经好几年没有接触它了,但经过我的努力,我设法使它起作用.
您所看到的问题似乎是由于(自动)重新计算Key View Loop而引起的.我必须通过黑客将其禁用,必须有一种更好的方法,但是我找不到它.
class MyWindow: NSWindow {
override func recalculateKeyViewLoop() {
// Remove. nextKeyView and makeFirstResponder seemed broken with this
}
}
摆脱重新计算后,您可以将初始响应者设置为:
override func viewWillAppear() {
view.window?.makeFirstResponder(aField)
}
如果您已经在界面生成器"中正确设置了所有nextKeyViews,则现在可以进行标签拖动.
还可以通过以下方式以编程方式完成设置:
override func viewDidLoad() {
super.viewDidLoad()
aField.nextKeyView = bField
bField.nextKeyView = cField
cField.nextKeyView = dField
dField.nextKeyView = aField
}
在上面的代码中,标识符aField
,bField
等是ViewController中的插座.您可以通过将控件从字段拖到视图控制器并命名来添加一个.
不是一个完美的解决方案,但我希望这会有所帮助.
I'm building an OS X Desktop app with Xcode 7.3 and I'm trying to set the tab order for one of the forms.
I've found a couple of posts explaining a similar problem for Xcode 4 but not getting anywhere with it, https://www.youtube.com/watch?v=SRrE8eqp0dU
The basic problem i'm trying to fix is when the user is in a field and tabs I want it to tab to the field below, not the field next to it, and so on.
Looking thru the documentation it mentions wiring up the nextKeyView so it knows where to tab next to, so I've used the Interface Builder to wire up the nextKeyView for each field to point to the right one but no go.
I think I need to set the initialFirstResponder but unsure where to wire that up?
It doesn't really attach to the separate view so bit lost.
I've posted my source code here https://github.com/johnantoni/osx-tab-order
Any ideas and pointers really welcome?
At a lose end.
I checked your project, excellent that you included it. It made playing around with AppKit easier. I am by no means an expert on AppKit, I frankly have not touched it in years but with some effort I managed to make it work.
Looks like the issues you are seeing are because of (automatic) recalculation of Key View Loop. I had to disable it with a hack, there must be a better way, but I could not find one.
class MyWindow: NSWindow {
override func recalculateKeyViewLoop() {
// Remove. nextKeyView and makeFirstResponder seemed broken with this
}
}
After getting rid of the recalculation you can set the initial responder as:
override func viewWillAppear() {
view.window?.makeFirstResponder(aField)
}
Tabbing now works if you have set all nextKeyViews properly in the Interface Builder.
The setup can also be done programmatically as:
override func viewDidLoad() {
super.viewDidLoad()
aField.nextKeyView = bField
bField.nextKeyView = cField
cField.nextKeyView = dField
dField.nextKeyView = aField
}
In code above, identifiers aField
, bField
etc. are outlets in the ViewController. You can add one by control dragging from the field to the view controller and naming it.
Not a perfect solution but I hope this helps.
这篇关于尝试在Xcode for OS X App中设置选项卡顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!