Re: NSPersistent Document but probably a Bindings Noobie Cry for Help
Re: NSPersistent Document but probably a Bindings Noobie Cry for Help
- Subject: Re: NSPersistent Document but probably a Bindings Noobie Cry for Help
- From: Quincey Morris <email@hidden>
- Date: Wed, 31 Dec 2008 12:42:34 -0800
On Dec 31, 2008, at 11:58, Richard Ashwell wrote:
4) The next task was based on a selection in the database table, I
wanted to programatically open a document and pre populate it from
the data.
It's not clear what you mean by "programmatically open a document".
Are you invoking the same action method that the Open menu item uses?
Telling the NSDocumentController to open a document? Trying to use
[[NSDocument alloc] init...]?
It also sounds like perhaps this programmatic "open" actually has the
semantics of "new". That is, you're creating a new (untitled) document
with some data from your database, which is (eventually) going to get
saved in a file separate from your database. If so, calling this
"open" is going to confuse us.
Here I ran into the issue that the document from the template was
tied to Nib via the Overridden windowNibName: method, which made it
difficult to programmatically get the Controller Window when
creating a new document from elsewhere in the code. The solution I
have here is to comment out the windowNibName method and instead
implement:
- (void)makeWindowControllers
{
NSWindowController *mainWindowController = [[NSWindowController
alloc] initWithWindowNibName:@"MyDocument" owner:self];
[mainWindowController setShouldCloseDocument:YES];
[self addWindowController:mainWindowController];
[mainWindowController showWindow:self];
}
It's not clear how this makes it easier to "get the Controller
Window", since the reference to the controller is local to this
method. Anyway, once the controller is created, you can always get it
as [[document windowControllers] objectAtIndex: 0].
This worked and I could instantiate an instance of my Document Class
programatically when ever I want and call method
makeWindowControllers on it and the document would come up, more
importantly I could then setup the instantiated Document to have its
data loaded.
If you really are invoking makeWindowControllers yourself, you
probably shouldn't be, since it's normally invoked automatically.
Invoking your implementation manually would create a second window
controller, which isn't what you want.
To create a new document programmatically, you should probably be
invoking [NSDocumentController openUntitledDocumentAndDisplay:error:].
Are you using something else?
_______________________________________________
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