iOS removing view
I have two views, viewA and viewB. I load viewB on top of viewA with
[self.view addSubview: viewB.view];
I wan't to remove viewB, but I don't how to do it. I tried
but this isn't working. How can I do this?
Call -removeFromSuperview on viewB.view.
To remove viewB's view from its superview, you need to call removeFromSuperview on that view.
From the UIView class reference.
Unlinks the receiver from its superview and its window, and removes it from the responder chain.
You are on the right track by using the removeFromSuperView. But you need to send the message to the view that you want to remove. Just as Till example
However, you might not have a handle to viewB by the time you want to remove it if you are not using property and synthesize method. I would make use of @property and @synthesize. So you can use:
Another way is using this: (assuming that your viewB.view is the last view you added to viewA.view
[[self.view.subviews objectAtIndex:(self.view.subviews.count - 1)]removeFromSuperview];
You can get a list of all subviews of your viewA by:
NSLog(@"subviews of viewA.view: %@",self.view.subviews);