Re: Connecting Actions to menu
Re: Connecting Actions to menu
- Subject: Re: Connecting Actions to menu
- From: Carlos Weber <email@hidden>
- Date: Sat, 16 Jun 2001 10:04:39 -1000
On Friday, June 15, 2001, at 11:38 AM, jgo wrote:
But "firstResponder" is not a static thing. Isn't the current
first responder dependent on the context and event? Let's
see, pp 132 et seq. from the anonymous "author": "Each NSWindow
in an application keeps track of the object in its view hierarchy
that has first responder status [gets first dibs on handling
an event]. [The first responder] is the NSView that currently
receives... events... any NSView within the window can become
first responder... You can also set the first responder
programmatically... the first responder object can be a target
of an action message sent by an NSControl, such as a button or
a matrix..." and then it goes on to say something similar to
what you do above, and equally contradictory. But, then
discusses the concept of an initial first responder.
If something is done in IB, it would be "static", defined
before compile, but what is the first responder is a
dynamic, execution time issue... or so I am led to believe.
Please, expostulate & clarify.
John, I am a cocoa newbie also. This "first responder" notion was one of
the most difficult things to wrap my mind around. Here's how I
understand it (others please feel free to correct me in case I still
haven't wrapped my mind around it!):
Designating the first responder object as the target of an (e.g., menu)
action is a way of telling the dispatch system (consisting, I think, of
code in NSResponder, NSApplication, and the ObjC runtime) that you are
designating an "id" to perform the action method, that the "id" is to
located and bound dynamically (at runtime), and that the way to locate
the particular "id" in question is to look at each object in the
responder chain until you find one that implements the designated action
method. In fact this is how menu items know whether they should enable
themselves or not! When I first figured out how this worked I was
dumbstruck by how cool and elegant it is.
One bit of explanation which helped me was in the 3d chapter of the
"Object-Oriented Programming and the Objective-C Language" book which is
available at Apple's website, or installed as part of the developer
tools on X, or in hardcopy from Fatbrain.com; it's the section called
"How Messaging Works", in Chapter 3 (The Objective-C Language).
Until it one day dawned on me, I had NO IDEA what to do with that "1"
staring at me in all my IB nib windows...
Hope it helps.