本文介绍了removeFromSuperview UIImageView 不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时送ChatGPT账号..我正在尝试使用以下代码从现有视图中删除图像:
I am trying to remove an image from an existing view using the code below:
-(void) deleteImage:(int)imageID{
//[self.imageArray removeObjectAtIndex:imageID];
//remove the image from the screen
for (UIView* view in self.view.subviews) {
if ([view isKindOfClass:[UIImageView class]] && [view tag] == imageID) {
//could be a bug here with the re-Ordering of the array (could add a helper method to reset all the tags on screen when this is called
NSLog(@"view %@", view);
//[self.imageArray removeObjectAtIndex:imageID];
[view removeFromSuperview];
}
}
}
NSLog 输出以下内容:
The NSLog outputs the following:
view <UIImageView: 0x18b8d7b0; frame = (0 0; 768 2016); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x18b8d890>>
我遇到的问题是它似乎正在获取 ImageView,但没有将其删除.
The issue i have is that it appears to be getting the ImageView but it doesn't remove it.
推荐答案
由于您正在尝试修改用户界面,因此您必须在主线程上进行.因此,请执行以下操作:
Since you're trying to modify the user interface, you must be doing it on the Main thread. Therefore, do the following:
dispatch_async(dispatch_get_main_queue(), ^{
[view removeFromSuperview];
});
这篇关于removeFromSuperview UIImageView 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论