R – Deleting UITableView sections combined with custom section headers UIViews = bug in Apple’s code

core-animationiphonensindexsetobjective cuitableview

I'm trying to delete a section from a UITableView using animation and custom table section header UIViews.

I use…

//Deletion from my model done here (not shown) and then perform the deleteSections...
[self.tableView beginUpdates];
[self.tableView 
  deleteSections:[NSIndexSet indexSetWithIndex:index]
  withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];

This works fine when I provide the section titles using

tableView:titleForHeaderInSection:

But when I provide my own custom header using

tableView:viewForHeaderInSection:

It deletes the desired section and shifts all the sections below it up. What I think is happening is it is asking for the new custom header just before it does the deletion animation. So it animates the removal of the desiredRow+1.

I end up with every section shifted up by one and a blank section at the bottom.

If I scroll to the bottom of the table then come back the sections are found properly again.

I don't think this is something I can fix. It seems like a problem in Apple's code handling section deletion with custom section headers. Usually it's a good idea to blame myself first 🙂 . I'm using the same logic to find the model object for my custom section headers vs. the NSString section titles so I cannot see how it could be a problem with my code.

Anyone know how to fix this or should I rethink my use of sections?

Best Answer

I was solved this issue to call reloadSections:atIndexPath: This is a one way. Other ways : Reload table (you may loose animation) Using a fetch controller and some property in u header view. When u delete one object fetch controller can do reload sections for u.

Related Topic