Re: Responder Chain and NSViewController in non-doc applications
Re: Responder Chain and NSViewController in non-doc applications
- Subject: Re: Responder Chain and NSViewController in non-doc applications
- From: Cathy Shive <email@hidden>
- Date: Mon, 30 Jun 2008 20:13:03 +0200
Hi Jerry,
NSViewController is a subclass of NSResponder, but there is nothing
provided in Cocoa that automatically includes the View Controllers in
your appliation's window's Responder Chain. You won't find any
documentation that will show you how NSViewController is included in
the Responder Chain, because it is not. You have to do this for your
View Controllers yourself.
This is part of the reason that Jonathan and I created the
XSViewController and XSWindowController classes you found in the blog
posts. When an XSViewController is added to the tree of view
controllers that the XSWindowController manages, the
XSWindowController patches it into the Responder Chain automatically.
If it is removed from the list, the view controller is removed from
the Responder Chain and the chain is patched back up by the Window
Controller.
In our design, the XSViewControllers are included in the responder
chain after the Window Controller, not in the part of the chain that
travels through the view hierarchy, but you could certainly do it how
ever you wanted to. Again, this post is just illustrating one way to
do it, there is no official Cocoa guide to adding View Controllers to
the Responder Chain.
If you explicitly set the target for an action in IB, you are right
that the action will get sent straight to its target without using the
Responder Chain. In the case of an application where the main menu,
the application's main window and all of its views are in the same nib
file, this could very well be a sufficient way to set up target/
actions in the app and you probably don't need any View Controllers at
all.
If you are setting up views in multiple nib files that will be swapped
in and out dynamically during runtime, you'll want to start thinking
about how to leverage the Responder Chain, NSViewController and the
handy "First Responder" object Interface Builder.
If you are new to Cocoa and just learning about the event system, I'd
suggest that you start with a simple UI, with everything in one nib
file and then start to strategize how you might expand your interface
into multiple nibs and View Controllers.
HTH,
Cathy
On Jun 30, 2008, at 6:52 PM, Jerry Isdale wrote:
I'm trying to understand a bit more about the Responder chain,
especially how it relates to regular (non-document) applications
using NSView and NSViewController added into the View Hierarchy.
Katidev.com has a nice series of articles on the related issue for
Document based applications. (It starts at http://katidev.com/blog/2008/04/09/nsviewcontroller-the-new-c-in-mvc-pt-1-of-3/)
However, it doesnt give me enough background to understand why I
need a XSViewController (extension of NSViewController), and how the
Controller hierarchy fits in with the View Hierarchy.
When does an application following the Responder Chain look at the
ViewController?
The clues I have (from KatiDev and Apple's "Cocoa Event-Handling
Guide" (aka EventOverview.pdf) is that the EVENT chain starts with
the current focus Window's First Responder, and then it traverses
the View Hierarchy's responder chain.... which I think means going
up to the parent (containing) view and checking its responder until
you get to the Window, then the WindowDelegate, and then the
NSWindowController.
Event Messages (aka events) dont get passed to the NSViewController
in the normal (NS) world. The XSController extension (katidev.com)
puts these back in, such that it when the event gets to the
XSWindowController it would get passed down the XS-responder chain
(see the article).
Action Messages (actions) follow a slightly different path. Actions
start by an Event responder (eg a ButtonCell) firing off a
sendAction:to:from. If there is a designated Target (to:) defined
by the responder, that object gets the action. Otherwise the
sendAction:to:from goes to the First Responder, up the view
hierarchy, to the NSWindow, to the WindowDelegate, to the NSApp then
the AppDelegate.
Again, the NSViewController doesnt appear in the responder chain,
unless it was designated by the initial Event Responder. If it was
designated, but doesnt respond, what happens? An Error or does it go
back to the responder chain?
The NSViewController is a Responder, but the associated view does
not patch it into the responder chain for either event or action
responding.
Correct?
But if my design explicitly specifies the target (connecting
IBActions in InterfaceBuilder), I dont have to worry about the
Responder chain for actions. Correct?
Thanks
Jerry Isdale
email@hidden
_______________________________________________
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
_______________________________________________
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