• 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
Re: Bindings related NSUndoManager problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bindings related NSUndoManager problem


  • Subject: Re: Bindings related NSUndoManager problem
  • From: Benjamin Stiglitz <email@hidden>
  • Date: Tue, 5 May 2009 11:10:36 -0400
  • Mail-followup-to: email@hidden

> Now I have come to implement Undo.  It actually works, but there is a
> problem (see below).  The code to implement Undo is in my view class:
>
> - (void)removePath:(PathElement *)oldPath
> {
> 	NSUndoManager *undo = [[self window] undoManager];
>
> 	[undo registerUndoWithTarget:self selector:@selector(addPath:)
> object:oldPath];
> 	[undo setActionName:@"Remove Object"];
>
> 	[paths removeObject:oldPath];
> 	[self setNeedsDisplay:YES];
> }
>
> - (void)addPath:(PathElement *)newPath
> {
> 	NSUndoManager *undo = [[self window] undoManager];
>
> 	[undo registerUndoWithTarget:self selector:@selector(removePath:)
> object:newPath];
> 	[undo setActionName:@"Add Object"];
>
> 	[paths addObject:newPath];
> 	[self setNeedsDisplay:YES];
> }

You're not sending KVO change notifications for the paths key, so the
observer isn't tearing down its observations when the path is removed.
See the NSKeyValueObserving Protocol Reference:

<http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Protocols/NSKeyValueObserving_Protocol/Reference/Reference.html#//apple_ref/occ/instm/NSObject/willChange:valuesAtIndexes:forKey:>

-Ben
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Bindings related NSUndoManager problem (From: Lawrence Manning <email@hidden>)

  • Prev by Date: Re: WTF? Is a file corrupted?
  • Next by Date: Re: Correct memory management in -awakeAfterUsingCoder: ?
  • Previous by thread: Bindings related NSUndoManager problem
  • Next by thread: How to play the next sound after the first sound is finished playing using AVAudioPlayer
  • Index(es):
    • Date
    • Thread