iOS TableView刷新cell section

2016-12-29  本文已影响226人  Lxin_
    NSIndexPath *indexPath=[NSIndexPath indexPathForRow:3 inSection:0];    
    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationFade];
    NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2];    
    [self.tableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationFade];

查阅了一些资料,对比reloadSections、reloadRows与reloadData的区别。

  1. 前两者可以加动画,后者不可以。
  2. 主要是性能的区别:三者的性能在100000次以内,相差无几。
  3. 数据源动态变化的情况下,例如在某些页面中,每个Section中的row是动态变化的,单独使用reloadSection会导致某些bug。而使用reloadData不会出现这个bug。
  4. 更多情况下,是搭配beginUpdates和endUpdates来实现 deleteSections:withRowAnimation:的功能。
上一篇下一篇

猜你喜欢

热点阅读