tableView代理方法的刷新

在不同需求下对tableView的刷新要求经常不一样,下面从不同程度上写一下tableView的刷新:

  • 整体刷新:

     [_tableView reloadData];
    
  • section部分刷新:

    - (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation NS_AVAILABLE_IOS(3_0);
    
    [self.tableView beginUpdates];
    [self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(2, 1)] withRowAnimation:UITableViewRowAnimationNone];
    [self.tableView endUpdates]; //从位置为2的section开始刷新1个section
    
  • 单独某条cell刷新:

    - (void)reloadRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation NS_AVAILABLE_IOS(3_0);
    
    [_tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow: 5  inSection:0]] withRowAnimation:UITableViewRowAnimationNone]; //刷新第0组第5条cell
    

其他

insertSections、deleteSections、moveSection; insertRowsAtIndexPaths、deleteRowsAtIndexPaths、moveRowAtIndexPath 都与 reload 类似。
插入/删除/移动操作一般与以下方法配合使用

  - (void)insertObject:(ObjectType)anObject atIndex:(NSUInteger)index;
  - (void)removeObjectAtIndex:(NSUInteger)index;
  - (void)replaceObjectAtIndex:(NSUInteger)index withObject:(ObjectType)anObject;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容