Everyone keep writing about deleting a section. Well, I can't seem to get one added.
Currently, I am trying like this (which fails with NSInternalInconsistencyException):
UITableView *tv = (UITableView *) self.tableView;
if ([tv numberOfSections] == 1)
{
[tv beginUpdates];
[tv insertSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationTop];
NSLog(@"Inserted.. Brace for impact.");
[tv endUpdates];
}
NSLog(@"Section count after update: %d", [tv numberOfSections]); // Never reached
If I am correct, inserting a section with index 0 should place it at the top, bumping all the other sections down, right? Well, if I write out the numberOfSections right after the insertSections, there appears to be no change in the number of sections.
Any ideas?
Johan
To add a section around some cells, start by placing a Section around it, optionally also adding a header and footer. As an example, we could create a row that holds task data for a reminders app, then create a list view that has two sections: one for important tasks and one for less important tasks.
UITableView with sections allows us to separate the list into different categories, so the list looks more organized and readable. We can customize sections as per our need, but in this tutorial, we are covering the basic UITableview with sections. Here's is the video if you prefer video over text.
Yes, thanks to both of you.
After some juggling, I finally managed to get it working. It was a combination of both your suggestions. The new data was never inserted, but also I did not have to increase the row count for the first item inserted, but only the second.
Did you also update your data source? You can't just update the table view without also updating the underlying data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With