Binding and Document-based application
Binding and Document-based application
- Subject: Binding and Document-based application
- From: Raphael Sebbe <email@hidden>
- Date: Tue, 20 Jan 2004 16:35:57 +0100
Hi all,
I made a post a while back on KVO unregistering in a document-based
app, and I think this mail may be of interest to those willing to use
Binding in document-based app.
For controller embedded in document NIBs, there is no problem at all.
The problems arise when you have GUI that are shared across documents
(ie, an inspector, etc.)
I got the suggestion from Scott to bind the NSObjectController to the
Shared Application's mainWindow.document. This works. But when the
document gets closed, you end up with that kind of message:
2003-12-23 13:00:22.854 XXXXXXXXXXX[1148] An instance 0x652910 of class
MADocument is being deallocated while key value observers are still
registered with it. Break on _NSKVODeallocateLog to start debugging.
This is due to the NSObjectController that is still "observing" the
document being deallocated.
Although I did find (crossed fingers, I was lucky) a way to remove the
observer, using [_myController unbind:@"contentObject"], this not a
"good" solution for me since:
- I have to keep outlets for all those global controllers (global ==
shared across documents)
- I have to rebind it manually once another document becomes the
current document
I have found another way of doing that, that is subclassing
NSApplication (and set it as the application class in the target) and
add accessors like this:
- (void)setCurrentDocument:doc;
- currentDocument;
Then, in the windowWillClose: and windowDidBecomeMain: notifications of
my document, I added appropriate invocations, respectively:
[NSApp setCurrentDocument:nil];
[NSApp setCurrentDocument:self];
And finally, bind my controller in IB to Shared Application's
currentDocument.
This seems to work right.
I would greatly appreciate if people experienced in using binding in
document-based app could comment on this or give their solution. IMHO
it is important to get clues/instructions on this from the ones "who
know", as binding is great piece of code and is welcome where
productivity is needed...
I also understand the Controller Layer is a "work in progress" (merge
with document architecture, etc.), but starting working with it now, on
real apps, is important.
Thanks,
Raphael
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.