NSPersistent Document but probably a Bindings Noobie Cry for Help
NSPersistent Document but probably a Bindings Noobie Cry for Help
- Subject: NSPersistent Document but probably a Bindings Noobie Cry for Help
- From: Richard Ashwell <email@hidden>
- Date: Wed, 31 Dec 2008 13:58:34 -0600
Ok,
First this is cry for help. Second I suck at the cocoa dev thing so I
anticipate that I won't even describe this very well, please forgive
my lack of skill in Cocoa Dev, but here goes:
I have built a relatively complex application, but have dug a whole I
can't fix or dig out of. I built the app on the Document Core Data
model, but this isn't really a core data issue (As in I haven't gotten
that deep into that part). My app was a little different (I think) in
that I wanted a controlling Main Window to be able to select / open
documents from rather than just the New/Open mechanisms provided by
the template.
To facilitate this
1) I overrode: applicationShouldOpenUntitledFile: to return NO so
that an untitled document wouldn't pop up.
2) Then I added a Window to the MainMenu Nib and added lots of code /
bindings etc to have a table of documents to choose from etc, the idea
here is there that the application overall is really a database of
individual documents.
3) I was pretty pleased to get all of this working, and the "New/Open"
still functions for opening or creating individual documents, so I
haven't broken anything there yet.
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.
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];
}
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. This all is
working with one exception:
Problem:
One view in my document nib is an NSTextView that I have A) Subclassed
and in IB set it to the Subclass, and B) IBOutleted to the main
document class for a variable there. Note this works when creating
new/open documents from the templates (I assume because the Nib
basically instantiates an instance of the sub class, and binds it for
me via the IBOutlet). Nice and dandy, however:
When I create the new document programatically (and I think/guess this
is my issue) perhaps I am getting two instantiations of the Subclassed
NSTextView or somehow when I create programatically my document class
isn't getting bound via the IBOutlet. I am only guessing and I don't
know how to troubleshoot here, which is why I am begging for help.
More details:
At this point I removed ALL functionality from the NSTextView subclass
leaving only a single method that is passed an
NSMutableAttributedString and all the method does is set the text
storage of itself and increases the font size etc, and again this
method is called and works via the new/open document stuff, but fails
when called programatically, I have traced to see that the string
passed in both cases is occurring, but since nothing shows up in the
view when I do it programatically, my only guess is that it is some
how a different instance of the subclass?
Any and all help is appreciated, I will happily code pieces etc, but
the application is a little large to link the whole thing here, but If
someone has any ideas please please, help me trouble shoot this.
Regards,
Richard Ashwell
_______________________________________________
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