NSUndoManager retains objects
NSUndoManager retains objects
- Subject: NSUndoManager retains objects
- From: Lorenzo <email@hidden>
- Date: Thu, 07 Apr 2005 10:33:04 +0200
Hi,
I have read the Raphael's fine RTF article about NSUndoManager. It helped me
a lot at understanding the way to use Undo properly. Thank you. Anyway I
have a question.
I have a hierarchical table view (Finder window style) and I add and delete
files and folders programmatically. So in my undo call, when I add a child I
have to tell the undoManager to delete that child from *its parent item*.
Therefore, I have checked, the parent item is retained by the undo manager.
- (void)addChild:(id)child toParent:(id)parent
{
int index = [parent addChild:child];
// now [parent retainCount] is 1
[[myUndoManager prepareWithInvocationTarget:self]
deleteItemAtIndex:index ofParent:parent];
// now [parent retainCount] is 2
}
- (void)deleteItemAtIndex:(int)index ofParent:(id)parent
{
id child = [parent childOfIndex:index];
[[myUndoManager prepareWithInvocationTarget:self]
addChild:child toParent:parent];
[parent deleteItemAtIndex:index];
}
So, let's say I add folder, then I add a file to that folder. The undoManger
retains the folder (which is the file's parent), so when I try to delete
that folder, I cannot succeed because it is retained by the undoManager.
How to solve this loop?
Best Regards
--
Lorenzo
email: email@hidden
_______________________________________________
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