我正在尝试使用以下代码从现有 View 中删除图像:
-(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 输出以下内容:
view <UIImageView: 0x18b8d7b0; frame = (0 0; 768 2016); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x18b8d890>>
我遇到的问题是它似乎正在获取 ImageView 但它没有删除它。
最佳答案
由于您正在尝试修改用户界面,因此您必须在主线程上进行。因此,请执行以下操作:
dispatch_async(dispatch_get_main_queue(), ^{
[view removeFromSuperview];
});
关于ios - removeFromSuperview UIImageView 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37271485/