美文网首页
OC TabelView笔记

OC TabelView笔记

作者: cry_0416 | 来源:发表于2016-10-15 16:29 被阅读23次

Cell复用

  • [tableView dequeueReusableCellWithIdentifier:@"cell"];

从复用池里取出可以复用的Cell(若没有,则取出来的是nil)

  • [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

从复用池里取可以复用的Cell,如果没有,则通过重用标识符自动创建对应的Cell

一些常用的TableView的API

  • [tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationBottom]

删除Cell,可以选择删除的动画

  • [tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationTop];

插入Cell,可以选择动画

删除或者插入Cell,一定要同步添加数据源

只会局部刷新数据,如果遇到一些奇奇怪怪的bug,可以尝试通过reloadData解决

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.35 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
               [tableView reloadData];
            });
    });
  • 选中Cell后自动恢复
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
  • 自定义Cell在- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier;方法里

tableView重点: 数据驱动UI改变

相关文章

网友评论

      本文标题:OC TabelView笔记

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