ios - 无法获取 UIView 的 subview

标签 ios objective-c uiview uiimageview

我在 vwProgress2 中添加了 3 个 ImageView ,标签分别为 100、101、102。但是,当我打印它的 subview 时,我的计数为 0..

enter image description here

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

最佳答案

使用 viewWithTag: 方法从标签获取 ImageView ,试试这个代码,

UIImageView *queProgress = (UIImageView *)[self. vwProgress2 viewWithTag: 100];
UIImageView *queTrue = (UIImageView *)[self. vwProgress2 viewWithTag: 101];
UIImageView *queFalse = (UIImageView *)[self. vwProgress2 viewWithTag: 102];

谢谢

关于ios - 无法获取 UIView 的 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36372414/

相关文章:

iphone - Cocos2d-iPhone中继承CCSprite

ios - objective-c : how to inherit category methods loaded in a parent class?

javascript - 在 xCode6/iOS-8 的 UIWebView 上停止滚动和弹跳

ios - 在 MPMoviePlayerController 之上添加 View

ios - 有关此 View 的信息

ios - NSURLSession后台传输: Callback for each video downloaded from a queue

ios - 如何检查 MPL Paypal 沙箱中的交易?

ios - View Controller Containment 在 iOS 5 中如何工作?

ios - 绘制 MKPolyline 填充颜色

iphone - 如何在Interface Builder中做UITextField的leftView?