Reputation:
My application contains a table view with rows and sections.
When I delete the last item of a section, I delete the section. It works fine.
But, when i move the last row of a section into another section, I get an error.
Here is my code in both cases :
[categoryArray removeObjectAtIndex:indexPath.section];
[tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationTop];
Here is the error that occurs in moveRowAtIndexPath:fromIndexPath:toIndexPath:
2009-03-11 17:56:09.524 Test[5140:20b] 1
2009-03-11 17:56:09.525 Test[5140:20b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]: index (5) beyond bounds (5)'
Any help would be great !
Upvotes: 3
Views: 1601
Reputation: 738
I had this issue and I just solved it. In my case, I was using Core Data, and I had to wrap the deletion logic in
[tableView beginUpdates];
...
[tableView endUpdates];
I had to wrap everything; from before I deleted the data/section until after I had saved the context. Hope it helps.
Upvotes: 0
Reputation:
Well, in fact, my code isn't trying to access to an element. I think the error come from a UITableView method (that I don't know because we only have access to header files of the sdk). The problem occurs at this point :
[tableView deleteSections:[NSIndexSet indexSetWithIndex:fromIndexPath.section] withRowAnimation:UITableViewRowAnimationTop];
Upvotes: 2
Reputation: 10728
It looks like you are trying to access the sixth element of a five-element array. Are you using the array size as the index without subtracting 1?
Upvotes: 0