NSObjectController and the undo manager
NSObjectController and the undo manager
- Subject: NSObjectController and the undo manager
- From: Dan Stein <email@hidden>
- Date: Fri, 4 Feb 2005 13:03:48 -0800
To use the undo manager with bindings to an array, apparently you need some sort of array that shadows the one in
your array controller and is, in fact, bound to a controller layer object.
Having read about the issue concerning the retain cycles for controller layer objects bound through File's Owner,
I implemented the workaround suggested by Scott Stevenson in the following:
http://www.cocoabuilder.com/archive/message/2004/7/28/113081
This recommends simply creating an instance of NSObjectController and setting its
content programmatically to your model objects or to a shadow array of model objects.
The latter solution DOES work, and eliminates the memory leaks from the retain cycle as advertised. Wonderfulness!
Sadly, it breaks any connections you have set up in your document or window controller to work with the undo manager.
In my app, this is just a nominal implementation with methods like
- ( void ) startObservingObject: ( id ) o;
- ( void ) stopObservingObject: ( id ) o;
- ( void ) insertObject: ( id ) o inArrayAtIndex: ( int ) index;
- ( void ) removeObjectFromArrayAtIndex: ( int ) index;
I implemented these in the window controller, but since this is no longer the object that is bound to the shadow
array of model objects in IB, there's certainly no use in making the WC the observer for any object in the array.
You get the undo manager from the DOCUMENT. Now it's beginning to look like you need an object controller
subclass able to get a reference to the document thereby to get the undo manager, so you can implement
the above methods and register undoable actions for the entities in the array that you are controlling
with this wonderful new object controller.
It makes sense that the window controller should not be stuck dealing both with maintaining the view and maintaining
a collection of model objects. If my surmise is correct, the new implementation is 'way cleaner in the MVC sense.
Am I on the right track here? This is NOT intuitive to anyone who has not already accomplished it once.
Dan
_______________________________________________
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