Vic*_*gel 15 uiimageview nsarray ios
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
imageView.image = [UIImage imageNamed:@"Sample.png"];
[self.view addSubview:imageView];
NSArray *subviews = [self.view subviews];
for(id element in subviews) {
if ([[element class] isKindOfClass:[UIImageView class]]) //check if the object is a UIImageView
{
NSLog(@"element is a UIImageView\n");
[element setCenter:CGPointMake(500., 500.)];
} else {
NSLog(@"element is NOT a UIImageView\n");
}
}
}
Run Code Online (Sandbox Code Playgroud)
我期望输出为"元素是UIImageView,但实际上元素不是UIImageView.为什么?不是有其他子视图.只有一个.此外,运行时,图像显示为100,100,而不是500,500正如所料.
Rah*_*ade 45
你的支票错了.你应该调用isKindOfClass:object而不是object类.
[element isKindOfClass:[UIImageView class]]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17350 次 |
| 最近记录: |