• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSUndoManager retains objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Prev by Date: Re: Accessing undo stack?
  • Next by Date: Re: ADC Core Data article
  • Previous by thread: Adding an NSImageView to an NSView [Updated]
  • Next by thread: GNU GPL Controller Layer for Sets
  • Index(es):
    • Date
    • Thread