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)
任何想法如何避免这种情况
只需检查视图是否为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)
| 归档时间: |
|
| 查看次数: |
3634 次 |
| 最近记录: |