美文网首页
tableView代理方法的刷新

tableView代理方法的刷新

作者: liailing | 来源:发表于2016-12-05 12:01 被阅读140次

在不同需求下对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;

相关文章

网友评论

      本文标题:tableView代理方法的刷新

      本文链接:https://www.haomeiwen.com/subject/jqvkmttx.html