Handling Undo/Redo in KVC To-Many Accessors
Handling Undo/Redo in KVC To-Many Accessors
- Subject: Handling Undo/Redo in KVC To-Many Accessors
- From: Sean Todd <email@hidden>
- Date: Fri, 7 May 2004 12:39:45 -0500
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.