美文网首页
解决复用cell控件重叠问题

解决复用cell控件重叠问题

作者: 213dfddbef5e | 来源:发表于2017-03-02 17:57 被阅读87次
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ThirdTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ThirdTableViewCell"];
    
    UILabel * label = (UILabel*)[cell.contentView viewWithTag:501];// ------先按照tag值试着去Cell中找,是否有标签

    if (label == nil) {// ------如果没找到再新建
        label = [[UILabel alloc]init];
        label.tag = 501;
        label.frame = CGRectMake(0, 0, 200, 20);
        [cell.contentView addSubview:label];
    }
    
    label.text = [NSString stringWithFormat:@"%ld", indexPath.row];

    cell.titleLabel.text = [NSString stringWithFormat:@"Section:%ld---Row:%ld", indexPath.section, indexPath.row];
    
    return  cell;
}

相关文章

网友评论

      本文标题:解决复用cell控件重叠问题

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