删除cell.contentview上除标签之外的所有子视图



如果我们使用以下代码,我可以删除包括textLabel在内的所有子视图。我需要删除除内容视图标题标签之外的所有内容

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];
    }
}

知道如何避免

只需检查视图是否为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
        }
}
}

最新更新