如果我们使用以下代码,我可以删除所有子视图,包括textLabel。我需要删除除contentview titlelabel之外的所有内容
for (int i=0; i < [self.mylist count]; i++) {
NSIndexPath *lIndexPath = [NSIndexPath indexPathForRow:i inSection:0];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:lIndexPath];
for (UIView *view in cell.contentView.subviews) {
[view removeFromSuperview];
}
}
任何想法如何避免
答案 0 :(得分:6)
只需检查视图是否为UILabel类型,即
for (int i=0; i < [self.mylist count]; i++) {
NSIndexPath *lIndexPath = [NSIndexPath indexPathForRow:i inSection:0];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:lIndexPath];
for (UIView *view in cell.contentView.subviews) {
if(![view isKindOfClass:[UILabel class]])
{
[view removeFromSuperview];
}
else
{
//check if it titlelabel or not, if not remove it
}
}
}