cell复用,状态改变

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"LeftTableViewCell";
    
    LeftTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    if (cell == nil) {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"LeftTableViewCell" owner:nil options:nil]lastObject];
    }else{//cell重用问题解决
        
        if (indexPath == lastIndexPath) {//点击cell的时候保存的
            cell.contentView.backgroundColor = [UIColor redColor];
        }else{
            cell.contentView.backgroundColor = [UIColor clearColor];
        }
    }
    cell.nameLabel.text = self.dataArray[indexPath.row];
    return cell;
}
原文地址:https://www.cnblogs.com/yipingios/p/4611304.html