删除cell.contentview除标签外的所有子视图
问题描述:
如果我们使用下面的代码,我可以删除包括textLabel的所有子视图。我需要除了内容查看titlelabel删除cell.contentview除标签外的所有子视图
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
}
}
}
又是怎么回事,如果去除标签有附加限制吗?例如,我想删除中间标签,但其下面的标签对被删除的标签有一个垂直限制。然后第二个标签不会填充已删除标签的空间。如何解决这个问题? – Slavcho 2013-11-08 08:54:16