0

So I have a UITableView with many sections, each section contains items with a certain letter of the alphabet(Alphabetically sorted). The user has the ability to add more data to this table, so when they add a new item that goes in a section that is not there, a new section must be created. Same problem when deleting, if the last item in a section is deleted the whole section would be removed. How would I animate this?

I have found something similar to this: UITableview reloaddata with animation

But that does not help me. It recommends using this method(In swift):

[_tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];

This works great if you have the same number of sections before and after the reload, but mine does not. The number of sections could change causing a crash.

Community
  • 1
  • 1
Arch
  • 127
  • 2
  • 12

1 Answers1

1

For the purpose you mentioned above, you should not reload data. For adding the new section you should use,

- (void)insertSections:(NSIndexSet *)sections
      withRowAnimation:(UITableViewRowAnimation)animation

For deleting the section you should use,

- (void)deleteSections:(NSIndexSet *)sections
      withRowAnimation:(UITableViewRowAnimation)animation
Apurv
  • 17,116
  • 8
  • 51
  • 67