Reputation: 1179
I'm developing a iOs app for iPad. I would like to delete two objects (UIImage and UIImageView) that are created by code.
UIImage *imatgetemporal = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
[popover dismissPopoverAnimated:YES];
UIImageView *img = [[UIImageView alloc] initWithImage:imatgetemporal];
How can I do it? Thanks!
Upvotes: 0
Views: 207
Reputation: 5887
An easy way to delete things is to set them to nil
. So you might have
img = nil;
You could keep the UIImageView alive but simply change out the image it displays by updating the image
property of the UIImageView with a new image.
When you remove an item from the superview you are simply taking it off of the screen. It is still in memory.
Something that is unclear to me from your code is how you are persisting the objects. I assume that you are setting the UIImageView
to a property somewhere. if that's the case, I would expect that your code above looks like (I am using a property called mainImageView for an example)
UIImageView *img = [[UIImageView alloc] initWithImage:imatgetemporal];
[self setMainImageView:img];
or you could even reuse the UIImageView
property you have each time (this assumes you only want to display one image at a time) and just replace the image with a new one.
UIImage *imatgetemporal = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
[popover dismissPopoverAnimated:YES];
[[self mainImageView] setImage:imatgetemporal];
Upvotes: 1