Re: Bindings related NSUndoManager problem
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