I am working with iPhone app(LandscapeRight Mode), I have added a Image view named imageView on my first page, but I have to delete it again on Third and fourth page. Please remember that I have to add this image again on Fifth page.
I added image with following code on first page :
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg_logo_medium.png"]];
imageView.frame = CGRectMake(123, 200, 250, 66);
imageView.tag = 800;
imageView.transform = CGAffineTransformMakeRotation(M_PI / 2);
//imageView.window.
[self.parentViewController.view.window addSubview:imageView];
[imageView release];
How this can be removed and re-added ?
When you want to remove
imageViewfrom its superview call:keep in mind that
imageViewreceives areleasewhen removed, so you need to ensure that it is properlyretained if you plan to reuse it. In other words, you will need to add an ivar to your controller class where you can retain the imageView for reuse. Actually you assign it to a local variable and at the end of the method you release; the variable should not be local, but a controller’s ivar so to have persistence, and you will need to release it in your controller’sdealloc.EDIT:
I suppose that you have a
UIViewControllersomewhere that can manage adding and removing subviews as you need it.In this class (I don’t know how to call it because you did not say it), I would declare a member to store the subview:
Here the implementation:
So, in
viewDidLoadyou create the imageView and store it internally for later use; When you need it, you add it by callingaddImageView; when you are done with it, you remove it withremoveImageView.If your class is not a view controller, you should be able to apply those same changes to it.