• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Question about relation between File's Owner, First Responder and controller object...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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 18:41:17 +0200

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.

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).

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.


The outlets from the SystemController instance in the NIB-file
is connected to the textfields in the window. Is that correct?
Or should it be a outlet from File's Owner?

The latter, for the very same reason.

In my SystemController class I have a method windowDidLoad but
this method is only called for one instance, File's Owner.

Sure it is. The other instance is completely superfluous.

Some items (e.g. New, Open) in the File menu are already
connected by InterfaceBuilder to First Responder.

The "non-standard" item in the File menu, are connected to
File's Owner. Is this correct?

Well, again -- it is correct, presumed the set up of the main menu in the same NIB as the (appropriate) File's Owner is what you truly want to, which I seriously doubt (see above).


Normally, the main menu should be in the MainMenu.nib -- application level -- where there is no document controller. Document-specific actions should be bound to First Responder. Only application-controller-specific actions can be bound directly (if there is such a controller at all).

So where shall the target/actions be connected? To the File's Owner
or the instance of SystemController?

In the MainMenu.nib to First Responder or the application-level controller instance, if any. In the Document.nib to First Responder or File's Owner (which represents the document-level controller).


Is it wrong to have an instance of SystemController in the NIB-file?

Presumed you use the standard Cocoa document architecture without serious tweaking, and presumed SystemController is your document-level controller (NSDocument subclass), it is wrong. Use File's Owner instead.


How can I add an item to the
File menu which shall be enabled when a document is open and
disabled when no document is open?

First Responder. It, kind of, dynamically changes to contain the currently active document if any; if there's no open document, it would contain no document, and thus the actions will be disable (in fact it is ***far*** more complicated, study NSResponder for details).


Why are there two instances of SystemController?

One was created for you by the framework as a standard service of the document architecture, the other you created yourself (by isntantiating it in the NIB).
---
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

  • Follow-Ups:
    • Re: Question about relation between File's Owner, First Responder and controller object...
      • From: Mikael Arctaedius <email@hidden>
References: 
 >Question about relation between File's Owner, First Responder and controller object... (From: Mikael Arctaedius <email@hidden>)

  • Prev by Date: Re: NSSpellChecker crashes after 64k words
  • Next by Date: Re: NSBezierPath geometry question...
  • Previous by thread: Question about relation between File's Owner, First Responder and controller object...
  • Next by thread: Re: Question about relation between File's Owner, First Responder and controller object...
  • Index(es):
    • Date
    • Thread