Re: is the nextKeyView really used by Cocoa ?
Re: is the nextKeyView really used by Cocoa ?
- Subject: Re: is the nextKeyView really used by Cocoa ?
- From: Ronald Bell <email@hidden>
- Date: Wed, 11 Jul 2001 18:04:13 -0500
My own intuition matches yours: once you have a textfield selected, and
you tab to the next one, the system should simply move to whatever is
indicated by that textfield's nextKeyView.
I have to admit that I thought this was a bug, and I reported it.
However, it apparently isn't. Apple's courteous tech support people
explained it this way: if the initialFirstResponder is not set, then IB
assumes that the rest of the nextKeyView chain wasn't set either, so it
is ignored. They didn't go into a lot of detail there, and it probably
isn't appropriate to criticize design choices when I don't understand
the underlying architecture of the system. In my own view though, it
violates what Peter Van der Linden calls "The Principle of Least
Astonishment." I think it would have been more intuitive to me for the
nextResponder chain to work like you're saying. Once you're in a
textField and you hit tab, the system seems like it ought to simply
refer to the nextResponder for that control. I suspect that controls
don't actually store their own nextResponder variable locally, but IB
presents it that way as a programming convenience.
Along those lines, I have been unable to get something similar to work:
I put a textField at the top in a window, and a NSTabView beneath that.
The NSTabView has two tabs, and inside each of the tabs' panels, I put
some textFields. I assign the top textField (which is outside the
NSTabView) to be the initialFirestResponder, and what I want to be able
to do is to tab from there to the first field of the NSTabView
(whichever tab is selected, I want to go to its first textField).
NSTabView has its own internal organization and initialFirstResponder
stuff inside (which you can see in IB, in the Instances panel, clicking
the tiny icon on the right side to switch to the outline-
view)(basically, inside the NSTabView is one NSTabViewItem for each tab
you want, and each NSTabViewItem has its own initialFirstResponder). For
each tab-pane, I connect that NSTabViewItem's initialFirstResponder to
the first textField in its respective pane, and the nextKeyView for my
very top textField (the one outside the NSTabView) points to the
NSTabView itself.
When I run this:
The top textField starts out highlighted, of course. Then I tab, and it
goes correctly to the first textField inside the tab-pane. Further
tabbing causes the cursor to traverse through the remaining textFields
of the tab-pane (of which there were several) and then back to the top
textField again (the last textField in each tab-pane being set so their
nextKeyView points back to that first outside textField).
That's what I expect. But then there is a problem. If I select the other
TabViewItem (click tab 2), things break:
I put my cursor in the top/outside textField. When I hit tab, it goes to
the first textField in the tab-pane. So far, so good. Further tabbing
either won't move the cursor -OR- suddenly NO textField is selected (as
if the cursor has somehow moved to an offscreen textField), and I get an
error beep with further tabbing.
And THEN, if I go back to the first tab-pane, which STARTED OUT working,
now it does the same thing.
NextStep has been through its paces for long enough that I doubt very
much this is really a bug, but I'm at a loss to know what I've missed.
regards,
ronald bell
>
Stephane Sudre wrote:
>
With the initialFirstResponder set, it's now working.
>
>
But I have no recollection of needed to set the initialFirstResponder to
>
make it work with some code on Mac OS X Server.
>
>
And I don't see the relation between the initialFirstResponder and the
>
nextKeyView mechanism.
>
>
The doc says:
>
>
setInitialFirstResponder:
>
>
<Attachment missing>
>
>
Sets aView as the NSView that's made first responder (also called the
>
key view) the first time the receiver is placed on screen.
>
>
If I make a tab in a NSTextField, I tend to believe the next key view is
>
the one you can get with the - (NSView) nextKeyView; method.
>
>
How does initialFirstResponder get involved here ?
>
>
The Key view loop is built by IB with the nextKeyView connection which
>
also gives the previousKeyView info. So why does it need to know the
>
initialFirstResponder ?
>
>
The initialFirstResponder is only useful for these cases: first time the
>
window is shown, tab when a view has no nextKeyView, isn't it ?