FROM : Mikael Arctaedius
DATE : Mon Apr 11 19:19:58 2005
2005-04-11 kl. 18.41 skrev Ondra Cada:
> Mikael,
>
> On 11.4.2005, at 18:08, Mikael Arctaedius wrote:
>
>> I have two books on Cocoa programming but I really can't find
>> enough information on this question in either book (neither
>> Hillegass nor Garfinkel&Mahoney speak a lot on this topic.)
>
> Myself, the original Garfinkel&Mahoney book (means the NeXTSTEP
> PROGRAMMING of 1993) helped much. But of course and naturally, the
> book (just like any other one) just gave the general directions; to
> understand somethnig fully, one needs to study the documentation :)
>
>> application has document specific menu items in the File
>> menu, i.e. items that should be enabled when a document is
>> open but disabled when no document is open.
>>
>> I have one NIB-file SystemWindow.nib which contains MainMenu,
>> File's Owner, First Responder, my Window and an instance of
>> my controllerclass, SystemController.
>
> Does not feel right. Generally, for a document-based application,
> there should be two NIBs:
>
> - MainMenu one, normally named "MainMenu.nib" containing the MainMenu
> (and of course, like all NIBs, File's Owner and First Responder). No
> window (well, it may contain some app-wide Preferences or Info or
> Inspector or whatever ones, but such things rather belong to a
> separate NIB anyway). It would contain a controller instance, in case
> there's a specific app-level controller (in simpler applications there
> tends to be no such beast, the document-level controller being
> sufficient for the functionality).
>
> - Document one, normally named after the document class. It contains a
> window (and perhaps some panels, views, contextual menus, other
> windows for multi-window documents, though again those rather belong
> to separate NIBs, whatever... and of course, like all NIBs, File's
> Owner and First Responder). Never though it should contain a main
> menu! Seldom enough it would contain the document-level controller
> instance, for the controller (your NSDocument subclass) is normally
> created by the framework code, before the NIB gets loaded.
>
>> The File's Owner is set to be an instance of SystemController.
>
> Wrong (unless your setup is quite weird).
>
> The Owner is some object which is *external* to the NIB (normally,
> though not necessarily, the very one which loads the NIB). Since you
> have the SystemController instance *inside* of the NIB, it does not
> seem reasonable to have another one for File's Owner.
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?
>> The buttons I've added to my window are connected to the
>> SystemController, i.e. Target/Action is set to point to a
>> method in SystemController. Is this right?
>
> Quite -- *presumed* the complete set up of the window AND the
> controller both in the NIB is what you truly want to, which I
> seriously doubt (see above).
>
> Normally, them buttons and similar would be linked to the File's
> Owner, which represents the controller to you (the controller being,
> as said above, external to the NIB).
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?
>> Or should they be connected to File's Owner? If a set a breakpoint in
>> the
>> action-method, I can see by looking at the value of self that
>> File's Owner is not the same instance as SystemController...
>
> See above. First step, remove the SystemController instance, and use
> File's Owner instead.
But File's Owner is an instance of my document class according to the
default setting of a newly created document-based application.
Either File's Owner should be an instance of my controller class
or I will need to add an instance to the nib file. Otherwise I
cannot see how to connect buttons to my action implementations
in the controller class?
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?
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.
Hoping for clarifcation...
Mikael Arctaedius
Stockholm, Sweden
DATE : Mon Apr 11 19:19:58 2005
2005-04-11 kl. 18.41 skrev Ondra Cada:
> Mikael,
>
> On 11.4.2005, at 18:08, Mikael Arctaedius wrote:
>
>> I have two books on Cocoa programming but I really can't find
>> enough information on this question in either book (neither
>> Hillegass nor Garfinkel&Mahoney speak a lot on this topic.)
>
> Myself, the original Garfinkel&Mahoney book (means the NeXTSTEP
> PROGRAMMING of 1993) helped much. But of course and naturally, the
> book (just like any other one) just gave the general directions; to
> understand somethnig fully, one needs to study the documentation :)
>
>> application has document specific menu items in the File
>> menu, i.e. items that should be enabled when a document is
>> open but disabled when no document is open.
>>
>> I have one NIB-file SystemWindow.nib which contains MainMenu,
>> File's Owner, First Responder, my Window and an instance of
>> my controllerclass, SystemController.
>
> Does not feel right. Generally, for a document-based application,
> there should be two NIBs:
>
> - MainMenu one, normally named "MainMenu.nib" containing the MainMenu
> (and of course, like all NIBs, File's Owner and First Responder). No
> window (well, it may contain some app-wide Preferences or Info or
> Inspector or whatever ones, but such things rather belong to a
> separate NIB anyway). It would contain a controller instance, in case
> there's a specific app-level controller (in simpler applications there
> tends to be no such beast, the document-level controller being
> sufficient for the functionality).
>
> - Document one, normally named after the document class. It contains a
> window (and perhaps some panels, views, contextual menus, other
> windows for multi-window documents, though again those rather belong
> to separate NIBs, whatever... and of course, like all NIBs, File's
> Owner and First Responder). Never though it should contain a main
> menu! Seldom enough it would contain the document-level controller
> instance, for the controller (your NSDocument subclass) is normally
> created by the framework code, before the NIB gets loaded.
>
>> The File's Owner is set to be an instance of SystemController.
>
> Wrong (unless your setup is quite weird).
>
> The Owner is some object which is *external* to the NIB (normally,
> though not necessarily, the very one which loads the NIB). Since you
> have the SystemController instance *inside* of the NIB, it does not
> seem reasonable to have another one for File's Owner.
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?
>> The buttons I've added to my window are connected to the
>> SystemController, i.e. Target/Action is set to point to a
>> method in SystemController. Is this right?
>
> Quite -- *presumed* the complete set up of the window AND the
> controller both in the NIB is what you truly want to, which I
> seriously doubt (see above).
>
> Normally, them buttons and similar would be linked to the File's
> Owner, which represents the controller to you (the controller being,
> as said above, external to the NIB).
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?
>> Or should they be connected to File's Owner? If a set a breakpoint in
>> the
>> action-method, I can see by looking at the value of self that
>> File's Owner is not the same instance as SystemController...
>
> See above. First step, remove the SystemController instance, and use
> File's Owner instead.
But File's Owner is an instance of my document class according to the
default setting of a newly created document-based application.
Either File's Owner should be an instance of my controller class
or I will need to add an instance to the nib file. Otherwise I
cannot see how to connect buttons to my action implementations
in the controller class?
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?
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.
Hoping for clarifcation...
Mikael Arctaedius
Stockholm, Sweden
| Related mails | Author | Date |
|---|---|---|
| Mikael Arctaedius | Apr 11, 18:08 | |
| Ondra Cada | Apr 11, 18:41 | |
| Mikael Arctaedius | Apr 11, 19:19 | |
| Ondra Cada | Apr 11, 22:36 | |
| Mikael Arctaedius | Apr 12, 06:16 | |
| Ondra Cada | Apr 12, 20:32 |






Cocoa mail archive

