Default Tableview - delete partitions

My application contains a table view with rows and sections.
When I delete the last element of a section, I delete this section. It works great.
But, when I move the last line of a section to another section, I get an error message.

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!

+3
source share
3 answers

Well, actually, my code is not trying to access the element. I think the error comes from the UITableView method (which I do not know, because we only have access to the sdk header files). The problem occurs at this point:

[tableView deleteSections:[NSIndexSet indexSetWithIndex:fromIndexPath.section] withRowAnimation:UITableViewRowAnimationTop];
+2

, . 1?

0

I had this problem and I just solved it. In my case, I used Core Data, and I had to wrap the delete logic in

    [tableView beginUpdates];
    ...
    [tableView endUpdates];

I had to wrap everything up; before I deleted the data / partition until I saved the context. Hope this helps.

0
source

Source: https://habr.com/ru/post/1704664/


All Articles