Changing Tab-Order (Focus) in a cocoa-App

357 Views Asked by At

I have a simple view with 4 textfields tf1 - tf4.

I want to set the initial focus on tf2, that works fine.

Then I want, that tf1 gets focus, then tf2 again - that does not work, the focus cycles through all 4 textfields.

I tried like this:

override func viewWillAppear()
{ super.viewWillAppear()
  tf2.becomeFirstResponder()

  tf2.nextKeyView = tf1
  tf1.nextKeyView = tf2
}

Where is my mistake?

1

There are 1 best solutions below

0
mica On

thanks @Willeke:

It works fine with:

override func viewWillAppear()
{ super.viewWillAppear()
  tf2.nextKeyView = tf1
  tf1.nextKeyView = tf2      
  self.view.window!.initialFirstResponder = tf2
}