美文网首页
UITableView粗解

UITableView粗解

作者: Gunks | 来源:发表于2018-03-31 14:55 被阅读0次

    设置有多少节-->设置每个节有多少cell-->设置每个节的样式节头(节脚)-->

    设置数据源(通过循环一个个加载每个节中的每个cell)

    重点:单元格重用

    目前已知3种方式,

    方法1 将获得cell的方法从

    - (UITableViewCell*)dequeueReusableCellWithIdentifier:(NSString*)identifier 

    换为

    -(UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath

    重用机制调用的就是dequeueReusableCellWithIdentifier这个方法,方法的意思就是“出列可重用的cell”,因而只要将它换为cellForRowAtIndexPath(只从要更新的cell的那一行取出cell),就可以不使用重用机制,因而问题就可以得到解决。

    方法2

    NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%d%d", [indexPath section], [indexPath row]];

    //以indexPath来唯一确定cell

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    通过为每个cell指定不同的重用标识符(reuseIdentifier)来解决。

    重用机制是根据相同的标识符来重用cell的,标识符不同的cell不能彼此重用。于是我们将每个cell的标识符都设置为不同,就可以避免不同cell重用的问题了。

    方法3

    删除重用cell的所有子视图

    相关文章

      网友评论

          本文标题:UITableView粗解

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