Re: Re: Handling Undo/Redo in KVC To-Many Accessors
Re: Re: Handling Undo/Redo in KVC To-Many Accessors
- Subject: Re: Re: Handling Undo/Redo in KVC To-Many Accessors
- From: Sean Todd <email@hidden>
- Date: Mon, 10 May 2004 15:40:09 -0500
Cc: email@hidden
From: Chris Giordano <email@hidden>
Subject: Re: Handling Undo/Redo in KVC To-Many Accessors
Date: Mon, 10 May 2004 10:15:05 -0400
To: Sean Todd <email@hidden>
<snip>
From some testing, it appears that it's crashing because it's
attempting to do something (probably restore) the selection in the
table, but since the selected indexes now extend past the end of your
array, it's complaining.
There are two things that I could see doing to fix this. The first is
probably easiest -- assuming that it works in all of your cases. That
would be to simply remove the selection when you delete. You could do
something to attempt to restore it (i.e., scan the previously selected
indexes/objects and reselect then once you're done with your delete).
Thanks for the feedback Chris.
Yes, adding one line of code is the simplest workaround:
- (void)removeObjectFromToDosAtIndex:(unsigned int)index
{
NSUndoManager* um = [self undoManager];
id item = [self objectInToDosAtIndex:index];
[[um prepareWithInvocationTarget:self]
insertObject:item inToDosAtIndex:index];
[toDoTableView deselectAll:self];
[toDos removeObjectAtIndex:index];
}
Of course, this is just doing programatically what was being done
manually by selecting another item in the table view before invoking
the undo command. However, I am still left wondering if this should be
needed in the first place (i.e. is this a bug with NSArrayController)?
After all, NSTableViews are often bound to array(like) objects via
NSArrayControllers. So I would expect the framework to handle any
paired calling of insertObject:in<key>AtIndex: followed by
removeObjectFrom<key>AtIndex: without getting confused.
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.