Re: Handling Undo/Redo in KVC To-Many Accessors
Re: Handling Undo/Redo in KVC To-Many Accessors
- Subject: Re: Handling Undo/Redo in KVC To-Many Accessors
- From: Don Briggs <email@hidden>
- Date: Mon, 10 May 2004 08:08:44 -0700
See
http"//homepage.mac.com/donbriggs
and download the
"ToManyDemo"
project.
It demonstrates a ToMany relationship.
It's undoable and AppleScriptable.
On May 7, 2004, at 10:39 AM, Sean Todd wrote:
Hi,
I am trying to handle undo/redo in insertObject:in<key>AtIndex: and
removeObjectFrom<key>AtIndex: but I am having trouble and I haven't
found anything in the archives addressing this issue. When I try to
Undo the creation of a new object in a mutable array I sometimes get
errors such as:
*** -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0)
at which time the undo manager is hosed.
I was able to reproduce this in the ToDos example project by modifying
the following 2 methods in MyDocument.m:
- (void)insertObject:(id)anObject inToDosAtIndex:(unsigned int)index
{
[toDos insertObject:anObject atIndex:index];
NSUndoManager* um = [self undoManager];
[[um prepareWithInvocationTarget:self]
removeObjectFromToDosAtIndex:index];
}
- (void)removeObjectFromToDosAtIndex:(unsigned int)index
{
NSUndoManager* um = [self undoManager];
id item = [self objectInToDosAtIndex:index];
[[um prepareWithInvocationTarget:self] insertObject:item
inToDosAtIndex:index];
[toDos removeObjectAtIndex:index];
}
If you create a new toDo object and then immediately try to Undo the
creation you get the error. But, if you create a new toDo object and
then deselect the item in the table before Undoingthen it works as I
would expect. Does anyone know what's going on here? Have I missed
something obvious (highly likely) or is this a bug that I need to
report? Any suggestions for a workaround?
Thanks,
Sean
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.