您的位置:首页 > 产品设计 > UI/UE

UITableViewCell重用问题,自定义与非自定义cell的两种处理方式

2015-03-28 10:07 405 查看
1.非自定义cell时采用下面的代码,可以避免重用问题


static NSString *cellIdentifier = @"workSearchTableCell";

workSearchTableCell *cell = (workSearchTableCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (cell == nil) {

        cell = [[workSearchTableCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];

    }else {

        while ([cell.contentView.subviews lastObject]!=nil) {

            [(UIView*)[cell.contentView.subviews lastObject] removeFromSuperview];

        }

    }

}

2.自定义cell时采用下面的代码,用上面的代码会发生cell滚动出显示位置后label文字消失


static NSString *cellIdentifier = @"cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (cell == nil) {

        cell = [[[b][b]tableView[/b] alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];[/b]

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: