Re: problems with tab key and custom views


Quincey Morris
 

On Dec 12, 2017, at 13:22 , James Walker <list2@...> wrote:

I have a window with 3 views that I want to be able to switch focus between using the tab or shift-tab keys.  Going by the view programming guide, it seems like I shouldn't have to do anything besides set up the nextKeyView loop in the nib and have my views return YES from acceptsFirstResponder, but that's not working.

You shouldn’t have to do anything else. I just tried it in a standard single-window document template with 3 text fields in the window, and it worked fine without any code.

Calling selectNextKeyView: does nothing.  Calling nextValidKeyView returns nil. 

I’ve never tried to use “selectNextKeyView:” but, looking at the documentation, it doesn’t seem to do the obvious thing (use the “nextKeyView” object). Instead, the documentation seems to say that it looks for the “closest” (geometrically, I assume) view in the rest of the next-view loop. This was consistent with my test. When I used “nextKey” to specify a different order for my text fields, the Tab key still jumped between them in geometry order.

Given all that, I’d have to assume that something is causing your window not to be key, or is causing something *else* in the window to be first responder — something at a different level in the view hierarchy. Do your 3 views have subview that can accept first-responder status? If you force one of them to be first responder, what does the Tab key do then?

Finally, don’t forget that windows have an “initialFirstResponder” property that you can use if its default initial choice isn’t what you want.

Join cocoa@apple-dev.groups.io to automatically receive all group messages.