Re: saveDocument:
Re: saveDocument:
- Subject: Re: saveDocument:
- From: Quincey Morris <email@hidden>
- Date: Wed, 09 May 2012 08:40:23 -0700
On May 9, 2012, at 02:45 , ecir hana wrote:
> I apologize but I still don't quite understand. If I just
> implement saveDocument: at the document and leave document controller
> without it, the menu item is still disabled. When I add saveDocument: to
> the controller as well, it works. I mean, if I try to visualize it, if I
> just alloc:init: a document it just floats there in memory, how would a
> menu know about it? So I need to create it via the document controller, no?
> If this is the case, how to propagate the saveDocument: event though
> the document controller to the document?
It's hard to know what you're asking, because you're either using the wrong terminology, or you're trying to do something very strange.
NSDocumentController is a frameworks object -- a singleton -- that provides shared behavior relating to all documents (such as maintaining the "Recent Documents" menu). Except perhaps in some extreme conditions, you wouldn't write your own. Very occasionally, it's necessary to subclass the NSDocumentController and force the singleton to your own subclass, but this is rare.
NSDocument -- well, your subclass of it -- is a *controller* object (in the MVC sense) that represents your document file and the windows used to edit it.
The NSDocumentController and your NSDocument-subclass instances are both in the responder chain. (There's a different responder chain running through each document object.) For information, see:
https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/EventArchitecture.html#//apple_ref/doc/uid/10000060i-CH3-SW9
and study the pictures under the heading "Responder Chain for Action Messages" -- especially figure 1-10 for document-based apps.
Thus, for example, the 'saveDocument:' action will be normally be delivered to the NSDocument-subclass object directly, because it is in the responder chain that's active when the menu item is chosen. Note that NSDocument *has* a 'saveDocument:' method; NSDocumentController doesn't.
The document architecture is described in great detail here:
https://developer.apple.com/library/mac/#documentation/DataManagement/Conceptual/DocBasedAppProgrammingGuideForOSX/Introduction/Introduction.html
You're absolutely wasting your time if you're trying to write Cocoa apps without understanding the event architecture (first reference, above). You're absolutely wasting your time if you're trying to write a document-based app without understanding document architecture (second reference).
_______________________________________________
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