KVO and inspectors in document-based apps -- best practice?
KVO and inspectors in document-based apps -- best practice?
- Subject: KVO and inspectors in document-based apps -- best practice?
- From: John Brownlow <email@hidden>
- Date: Thu, 31 Mar 2005 12:22:37 -0500
I've seen this question asked before but not answered so I hope someone
will step up.
I have a document-based app which has several inspector windows which
are independent of any particular document. The window controllers for
these windows are owned and operated by the application's delegate.
They update themselves to reflect whatever the current document is.
I do this by (in IB) binding UI elements and NSArrayControllers to the
respective window controller's -currentDocument method, implemented
like this:
@implementation GLInspectorController
- (NSDocument *)currentDocument
{
return [[NSDocumentController sharedDocumentController]
currentDocument];
}
@end
However, when I close the document, I get an error to the effect that
the document is being deallocated while there are still KVO observers
registered.
As I see it there are two options... either
1. Have the document explicitly check in and out with the application
delegate and have all the inspector windows bind to an iVar in the
application delegate. I think this would work but I would rather rely
on the sharedDocumentManager to judge what is the current document. I
don't see why the document itself should have to worry about it.
2. In the document's dealloc method, unbind all registered observers
before [super dealloc]. Problem is, I don't know how to do this.
NSKeyValueObserving declares a method that seems appropriate but the
documentation is entirely opaque... it just says...
- (void *)observationInfo
Returns a pointer that identifies information about all of the
observers that are registered with the receiver, the options that were
used at registration-time, etc. The default implementation of this
method retrieves the information from a global dictionary keyed by the
receiver’s pointers.
So what is the best practice for binding inspector windows to the
current document??
--
John Brownlow
Deep Fried Films, Inc
http://www.johnbrownlow.com
http://www.pinkheadedbug.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden