Re: Programmatically switching text fields
Re: Programmatically switching text fields
- Subject: Re: Programmatically switching text fields
- From: Graham Cox <email@hidden>
- Date: Mon, 03 Aug 2015 14:53:05 +1000
> On 3 Aug 2015, at 2:28 pm, Ken Thomases <email@hidden> wrote:
>
> The default implementation of -canBecomeMainWindow returns NO for panels. Is your window intended to be the main window? Is it actually? Does it change anything if you add an override to return YES?
Well, it doesn’t need to be main, it only needs to become key. Overriding it is a pain because all the custom code is in a NSWindowController subclass, so needing an additional NSPanel subclass creates a lot of development friction. However, since I have now fixed this, it’s a moot point...
> Are you aware that NSTabViewItem has its own initialFirstResponder property? Have you tried using that?
That makes total sense, and I wasn’t aware of it. However, it doesn’t fix the problem in this case - it acts the same way as having it be the window’s initialFirstResponder..
What has worked is a) implement the tab view delegate to request that the window selects the first field by invoking -selectKeyViewFollowingView:, passing its predecessor, and b) remove all the code I had added in various places to try and force the first responder to be the first field (e.g. calling makeFirstResponder from -windowDidLoad). This is OK for my case, because the fields all live on the tab that isn’t shown initially, so there will always be a tab switch before the user sees the field for the first time. Reselecting that field if they switch away and back is OK as well.
I don’t think this is a very general solution, but it may well be that for fields on the default tab, initialFirstResponder on the window or tab view will work (not tried). Does seem a bit buggy overall though, in the rush to animate everything (key focus ring here) some basic functionality has got broken.
—Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden