我在vwProgress2
中添加了3个图像视图,分别带有标记100,101,102。但是,当我打印其子视图时,我得到0计数..
NSLog(@"%d",[[vwProgress2 subviews]count]);
for (UIView *subView in vwProgress2.subviews) {
if ([subView isKindOfClass:[UIImageView class]] && subView.tag >= 100) {
[(UIImageView *)subView setImage:nil];
NSLog(@"Hello");
}
}
可能是什么原因?我已经设置了IBOutlet
。
答案 0 :(得分:1)
使用viewWithTag:方法从标签获取图像视图,尝试此代码,
UIImageView *queProgress = (UIImageView *)[self. vwProgress2 viewWithTag: 100];
UIImageView *queTrue = (UIImageView *)[self. vwProgress2 viewWithTag: 101];
UIImageView *queFalse = (UIImageView *)[self. vwProgress2 viewWithTag: 102];
谢谢
答案 1 :(得分:0)
UIImageView *queProgress = (UIImageView *)[self.view viewWithTag: 100];
UIImageView *queTrue = (UIImageView *)[self.view viewWithTag: 101];
UIImageView *queFalse = (UIImageView *)[self.view viewWithTag: 102];