Re: Question about relation between File's Owner, First Responder and controller object...
Re: Question about relation between File's Owner, First Responder and controller object...
- Subject: Re: Question about relation between File's Owner, First Responder and controller object...
- From: Ondra Cada <email@hidden>
- Date: Mon, 11 Apr 2005 22:36:58 +0200
Mikael,
On 11.4.2005, at 19:19, Mikael Arctaedius wrote:
OK, so I have an instance of my controller inside the document nib
file?
And the File's Owner in MainMenu is an instance of NSApplication and in
the document nib file File's Owner is an instance of my document class?
Is that correct?
Could be, if there is some quite special need to do it this way.
Normally though, the NSDocument subclass -- the document NIB's File's
Owner -- is the document controller.
Well, the implementation of the button actions are inside the
SystemController why I must connect them to the instance of
the SystemController. I cannot connect them to the File's
Owner any more since it is an instance of the document class which
doesn't implement the button actions. But maybe the implementation
of button actions should be inside the document class?
Yup, along with all the other document controller code. Or is there a
reason against in your case?
There are more questions but I think these are the two major
questions:
Should the document nib file's File's Owner be an instance of
my document class or my controller class?
Both :), since your document class is the (document-level) controller.
If File's Owner is an instance of my document class where
does the implementation of action methods belong? I have
learned to put them in the controller class which would force
me to an instance of the controller class to the nib file.
This can be done too, if need be, but why? Is there a reason you are
doing it this way?
Anyway, if you want to, you *can* split the functionality, if you want
to. For actions triggered by the main menu you'll have though to ensure
re-direction from the NSDocument subclass (which is, from the document
system POV, *the* document controller and which thus lives in the
Responder Chain) to your own SystemController, like this:
@interface MyDocument:NSDocument {
IBOutlet SystemController *controller; // in NIB, this File's Owner
outlet is bound to the SystemController instance
...
}
@end
@implementation MyDocument
...
-(IBAction)thisIsSomeActionOfSystemControllerCalledFromMainMenu:sender {
[controller
thisIsSomeActionOfSystemControllerCalledFromMainMenu:sender];
}
...
@end
In the MainMenu, you'll connect the menu action to First Responder.
That will ensure the appropriate NSDocument subclass (of the active
window) would get the message, and the redirection then would ensure
the SystemController instance of yours--instantiated from the NIB--gets
the message to do the work.
There are other ways too, but I guess this would be the simplest one
(that is, after removing the SystemController class altogether, moving
its functionality into your NSDocument subclass where it conceptually
belongs to :))
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden