当我们有时候用tableview写控件时,经常出现上下拖动后控件在一个cell上重复了,为此在重用时需要把其子视图先删除或归零
static NSString *identifier = @"identity";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];if (!cell) {
//cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:identifier];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}else{
// 删除cell中的子对象,解决覆盖问题。
while ([cell.contentView.subviews lastObject] != nil) {
[(UIView*)[cell.contentView.subviews lastObject] removeFromSuperview];
}
}