3

I am trying to set the tab order for NSTextFields on a given NSView. As far as I understand it I have to connect the NSTextFields with InterfaceBuilder by setting the nextKeyView outlet to the next NSTextField. I did this - and there is no effect. When I press tab, after being in one of the NSTextFields it just loses focus and that is it. No matter how often I press tab none of the other NSTextFields regain focus.

I also read that I need to set the initialFirstResponder of the window. I don't think I can do this in this particular case, because my AppDelegate calls up a NSView which in turn acts as a Menu-Area with many different buttons, which each call up different NSViews that are loaded as subviews of a different view. Therefore the AppDelegate has no way of knowing which NSView is currently loaded.

Is there a way to set the tab-order of NSTextFields on an NSView-basis?

Thanks

Joseph
  • 9,171
  • 8
  • 41
  • 67

2 Answers2

1

You have to disable auto-recalculation of the key loop in the window. See -[NSWindow setAutorecalculatesKeyViewLoop:].

Edited to add: this can be set in Interface Builder, too.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • Did not work. I added [_window setAutorecalculatesKeyViewLoop:NO]; to the applicationDidFinishLaunching method. In Interface Builder I did not have the checkbox "Auto Recalculates View Loop" ticked in the firstplace. – Joseph Apr 11 '12 at 17:58
  • Is it that you want to customize the tabbing order, or you just want tabbing to work at all and it isn't? If the latter, have you tried *enabling* automatic recalculation of the key view loop? – Ken Thomases Apr 11 '12 at 19:47
  • I tried activating the Auto Recalculates View Loop Option, but it had no effect. And basically I want tabbing to work at all... Currently if I tab "out of" a NSTextField it loses focus and nothing else happens... Nothing else gets focused - no matter how often I press tab... – Joseph Apr 12 '12 at 05:55
0

This may or may not help for your situation, but the following worked for me when dealing with an NSView within another NSView. I had two vertical stacks of NSTextFields. Rather than traversing horizontally, I needed to tab down one stack and then the next... So I embedded each of the two vertical stacks in their own box (In IB, first select your items, Editor> Embed In> box). Works perfect. If you don't want the look of a box, you can clear its title and set its border type to none: invisible box.

averageJoe
  • 11
  • 4