-(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");
}
}
}
내가 요소가있는 UIImageView입니다 "로 출력을 예상을 행동을 왜 이해가 안하지만 요소가있는 UIImageView 아닙니다 사실의 그것은 아니다 왜 다른이 있다는 것을 .. 실행할 때 파단 하나가 또한, 이미지는 예상대로되지 500500, 100100에 표시됩니다isKindOfClass 사용 :.?이 코드는이 방법
id 대신 UIImageView를 사용하도록 코드를 변경해 보았습니다. 그 결과는 동일했습니다. –
id를 참조로 사용할 수 있습니다. 당신이 놓치고있는 것은 잘못된 방법으로 isKindOfClass 메서드를 호출하고 있다는 것입니다. 내 대답을 확인해. –