解决UITableView复用

作者: 小熊翻译App | 来源:发表于2017-06-27 20:28 被阅读42次

解决复用的写法1:

// 通过indexPath创建cell实例 每一个cell都是单独的
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        if (!cell) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellId];
        }

解决复用的写法2:

// 定义cell标识  每个cell对应一个自己的标识
        NSString *cellId = [NSString stringWithFormat:@"cell%zd%zd",indexPath.section,indexPath.row];
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if (!cell) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellId];
        }

相关文章

网友评论

    本文标题:解决UITableView复用

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