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: Richard Ashwell <email@hidden>
- Date: Wed, 31 Dec 2008 17:01:12 -0600
Sweet!!!! Sweet!!! Magic!!! the :
NSError *error;
MyDocument *newDoc = [[NSDocumentController
sharedDocumentController] openUntitledDocumentAndDisplay: YES error:
&error];
was the key, thank you so much Quincey!!! This both instantiates and
lets me controll what is created!
Yeah!! What a great end to the year, i'll actually go into the new
year with working code :)
Regards,
Richard
On Dec 31, 2008, at 4:27 PM, Quincey Morris wrote:
On Dec 31, 2008, at 13:49, Richard Ashwell wrote:
1) I am/was creating my document class "programatically" like:
(Note Typed in email, and in my project MyDocument is actually
named something else)
MyDocument *newDoc = [[MyDocument alloc] init];
[newDoc importData:data];
Not so good. When creating or opening a document, there's more to do
than just creating the NSDocument instance.
openUntitledDocumentAndDisplay:error: is the way to go.
By itself this wouldn't pop up a document because of the overridden
applicationShouldOpenUntitledFile: method
No, that had nothing to do with it. By creating the NSDocument
instance directly, you simply weren't getting the document window
shown.
So I added:
[newDoc makeWindowControllers]; and the method mentioned below.
Reading your notes carefully though it looks like I maybe should be
using openUntitledDocumentAndDisplay:error instead of the
makeWindowController thing that got my document to popup perhaps
only because I added the showWindow:self to the end of that method.
Exactly.
And you are probably right that I am getting two instantiations,
but only "seeing" one.
I will test your suggestion first, though It might take me a few
because the template doesn't generate a NSDocumentController, only
the NSPersistentDocument class itself so I first have to figure out
how to add the Controller to my AppController class and stuff
without breaking everything, I should be able to get
openUntitledDocumentAndDisplay:error to work (I bet it does, so
here is a pre thank you!!!),
No need to stress! NSDocumentController is a singleton object that
every AppKit application gets for free. So instead of:
MyDocument *newDoc = [[MyDocument alloc] init];
just write this:
NSError *error;
MyDocument *newDoc = [[NSDocumentController
sharedDocumentController] openUntitledDocumentAndDisplay: YES error:
&error];
if (!newDoc)
... // report the problem described in 'error'
... I pulled out the extra call to makeWindowControllers and
traced, When the document gets create via the New menu item the
makeWindowControllers gets called automatically like you described,
but just instantiating the document with MyDocument *newDoc =
[[MyDocument alloc] init]; doesn't call makeWindowControllers.
Perhaps that is what the NSDocumentController is supposed to do for
me?
Yup. It also causes the document to appear on the Window menu for
you, and populates the Open Recent menu.
_______________________________________________
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
_______________________________________________
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