1. insert or delete sections/rows可能出现的Crash
当tableView数据源发生变化需要更新视图时,最直接的方式是直接调用reloadData方法,然而如果我们的tableView数据源巨大时,会造成很多不必要的方法调用。
例如有如下程序:
每当点击update时,会向tableView的数据源数组中增加两条数据,更新UI,如果我们直接调用reloadData来更新UI,会是的前面没有任何改变的4行也被刷新一遍,造成性能损失。
因此通常数据源中局部数据更新时我们会调用UITableView的以下几种方法:
- (void)beginUpdates;
- (void)endUpdates;
- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)insertRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
- (void)deleteRowsAtIndexPaths:(NSArray<NSIndexPath *