Re: How to set tab order in a window that has view swapping

Christiaan Hofman <[email protected]> Tue, 25 Jan 2011 13:08:51 +0100
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
On Jan 25, 2011, at 8:20, Abhijeet Singh wrote:

> Hi,I have a single window with a toolbar and a custom view in my application. Toolbar has Back and Next button on it. This is my MainMenu.xib.I have 5 more xibs other than the MainMenu.xib in my application. Each xib contains one view with different controls in it.On Next and Back button click on my Main window the current view is swapped with another view. On my first view there is a NSPopupButton. I want when the first view is displayed the keyboard focus should be on NSPopupButton and on tab key press it should move to next control in the tab order. Basically I want my user to be able to use the tab control to change the keyboard focus in all my views.Thanks & RegardsAbhijeetDear macosxdev ! Get Yourself a cool, short @in.com Email ID now!

You can either have the window auto recalculate the keyview loop, in which case you don't have to do anything yourself, but the system will determine the exact order. If you want to control the order yourself, you'll need to update the tab view order yourself programmatically. In that case, you can set the order in the NIBs for the individual views you swap in, by connecting the nextKeyView outlets, and whenever you swap in a new view, you should connect the first and last view in the new view's loop to the rest of the loop in your window. To set the initial focus, you can use -[NSWindow makeFirstResponder:], which you can do in a method like windowDidLoad.

Christiaan