1

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 NSTextFields. 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 NSTextFields, 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+.

Stephen Booher
  • 6,522
  • 4
  • 34
  • 50

2 Answers2

3

Make sure that you also set the initialFirstResponder outlet of the window to the first field (the table view in this case).

omz
  • 53,243
  • 5
  • 129
  • 141
0

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.

Anne
  • 26,765
  • 9
  • 65
  • 71
Wienke
  • 3,723
  • 27
  • 40
  • Why do I have to do it programmatically? What if the user wants to shift+tab? For what it's worth, I did try this, but it didn't work. One problem is that NSTableView doesn't send a controlTextDidEndEditing notification to its delegate when you tab away from it. Even on the NSTokenField and NSTextFields, which do fire off the notification, the makeFirstResponder message did not seem to change the tab order. Finally, I'm not sure using IBAction on the fields would work for me because I think that would fire when the enter key was pressed, and I don't want to change fields when enter is pressed. – Stephen Booher May 17 '11 at 15:16
  • If nothing else works, you could try capturing key events. All your controls are subclasses of NSResponder, so if you subclass them, you can customize NSResponder's keyUp method. Test if the event is a tab or shift-tab. If not, do nothing. If so, find out from the window which control has firstResponder status so you know where you are, and go from there. (For this to work, you do have to be able to use makeFirstResponder. It’s worked for me for both buttons and textfields. Maybe try adding a 0.1 delay?) Also, you probably need to remove conflicting nextKeyViews in IB. – Wienke May 18 '11 at 17:29