Re: currentDocument
Re: currentDocument
- Subject: Re: currentDocument
- From: "Michael Ash" <email@hidden>
- Date: Wed, 3 Dec 2008 00:11:09 -0500
On Tue, Dec 2, 2008 at 11:06 AM, gMail.com <email@hidden> wrote:
> Hi,
> I use to get the currentDocument this way
> [[NSDocumentController sharedDocumentController] currentDocument]
> It works well but not in the following case
>
> My apps opens automatically a document with
> - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName
> error:(NSError **)outError
> Here I load my docFile in a NSDictionary mDocDict
>
> Then, later in the method
> - (void)windowControllerDidLoadNib:(NSWindowController*)aController
> I really build my objects using the dictionary mDocDict. But at this point
> [[NSDocumentController sharedDocumentController] currentDocument]
> returns nil and I can't get some variables I really need.
>
> How to fix this?
> The Docs suggest to use
> [[[self window] windowController] document];
> But I can't really use this solution all over my code. Some objects have no
> window.
You really can't use -currentDocument in this way. That just gives you
whatever document is "active" for the user. You have no guarantee that
this will be the document that's actually involved in whatever object
you're manipulating.
In your example you already have a window controller, so why can't you
just do [aController document]?
In the more general case, you just need upward links in your objects
to either the document or something that has a pointer to the
document, such as a window controller. If you're in a nib then you can
use IBOutlets to do this, otherwise you might want to declare some
sort of "parent" or "owner" ivar that the controlling object can set
to point back to itself.
Mike
_______________________________________________
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