Header below a section gets duplicated if a row is deleted from the section above
In the editing mode of one of my tableviews, I delete a row from a section. The section below has a header. The deletion of the row in the section above leads to duplication of the section header below. So I have 2 header titles, one above the other.
I also tried forcing a reload of the section after the delete to no avail:
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
NSIndexSet * inde开发者_如何学运维xSet = [[NSIndexSet alloc] initWithIndexesInRange:NSMakeRange(3,1)];
[self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationFade];
[indexSet release];
[self.tableView endUpdates];
Any ideas of what I have done wrong?
It is also interesting that the header that failed to get removed is not "seen". If I scroll right off the content of the table view, and let it snap back, only the top header view is seen. It always ignores the header that should have been removed.
I have tried in different ways, (commented code) but at last the begin and end updates technique works. thanks Megasaur.
[self.tableView beginUpdates];
[tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
[tableView scrollRectToVisible:[tableView rectForSection:section] animated:YES];
//[tableView setNeedsDisplay];
//[self.view setNeedsDisplay];
[self.tableView endUpdates];
Although I haven't used multiple sections, I have had a similar issue with a single section. If you don't change the underlying data source (the count of the number of items being key) the table view doesn't render properly. I would make sure that your underlying data source has the row removed before you update the display.
Table section collapse/expand seems do not work properly. It would be great it worked. I took an alternative approach to implement my target. I use a scrollview to contain all other view and tables. By this way I am having some problem to capture cell selection since I used separate view controller for each section (now View).
精彩评论