> 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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com