问题
I have a window with two columns of fields. On the left, there is an NSTableView
and an NSTokenField
, and on the right, there are two NSTextField
s. I want the tab order to go down the left, then down the right. (So the order should be NSTableView
, NSTokenField
, NSTextField
, NSTextField
in my window.) However, Cocoa appears to be determining its own preferred order, going from the top to the bottom. The NSTokenField
is positioned lower in the window than any other control, so it will always tab from NSTableView
, to the right NSTextField
s, then back to the bottom left NSTokenField
.
I have tried following this section of the Apple developer documentation called Enable Tabbing Between Text Fields and dragging nextKeyView in Interface Builder between the fields in the order that I want. This seems to have absolutely zero effect on the tab order, and from what I can tell, Cocoa appears to still use its default detecting method to choose a tab order.
Any ideas? My target is 10.6+.
回答1:
Make sure that you also set the initialFirstResponder
outlet of the window to the first field (the table view in this case).
回答2:
Sounds like you're going to have to do it programmatically:
Register for controlTextDidEndEditing
notifications, identify the field by tag, and then call makeFirstResponder:fieldOfYourChoice
on the window. And/or use an IBAction
on the field, identifying it by sender
, and call makeFirstResponder
.
来源:https://stackoverflow.com/questions/5997997/setting-a-custom-tab-order-in-a-cocoa-application