gpt4 book ai didi

ios - 使用 isKindOfClass : I don't understand why this code is behaving this way

转载 作者:IT王子 更新时间:2023-10-29 08:22:05 24 4
gpt4 key购买 nike

-(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");
}
}
}

我希望输出是“element is a UIImageView, but it's actually element is NOT a UIImageView. 为什么?不是有其他 subview 。只有一个。此外,运行时,图像显示在 100,100 ,而不是预期的 500,500。

最佳答案

您的支票有误。您应该在对象而不是对象类上调用 isKindOfClass:

[element isKindOfClass:[UIImageView class]]

关于ios - 使用 isKindOfClass : I don't understand why this code is behaving this way,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13619477/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com