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

AMH*_*AMH 1 iphone uitableview uiview ipad

如果我们使用以下代码,我可以删除所有子视图,包括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];
    }
}
Run Code Online (Sandbox Code Playgroud)

任何想法如何避免这种情况

Kin*_*iss 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
        }
}
}
Run Code Online (Sandbox Code Playgroud)