【发布时间】:2016-05-17 08:55:42
【问题描述】:
我正在尝试使用以下代码从现有视图中删除图像:
-(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 但它没有删除它。
【问题讨论】:
-
能否请您详细说明一下要求。您真的需要删除
imageView本身还是只清除imageView显示的图像? -
@GoGreen 我需要删除 imageView 本身
-
在从 superView 中删除之前,您已经记录了该语句。尝试在 for 语句之后循环遍历子视图以检查
imageView是否仍然存在。此外,这不是删除子视图的理想方式。通过将其添加为property或instance variable来保留对要删除的视图的引用。然后,您可以使用此参考将其删除。请再次检查。
标签: ios objective-c xcode uiimageview