解决复用cell控件重叠问题

2017-03-02  本文已影响87人  213dfddbef5e
- (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;
}
上一篇 下一篇

猜你喜欢

热点阅读