iOS - removeFromSuperview removing too many views
In my app I have my MainWindow, View1, and View2.
View1 is loaded via a button press in the MainWindow and View2 is loaded via a UITableView in View1.
So I call [self.window addS开发者_JS百科ubview:View1]
then [self.view addSubview:View2]
.
When I close View2 with [self.view removeFromSuperview]
I end up back act the MainWindow and not View1 for some reason.
Any ideas as to whats going on?
You need to ensure that self.view points to 'View2'. That will depend on where you are calling [self.view removeFromSuperview]
.
If you aren't calling inside the controller for View2, then this might work anywhere else you have a reference to it:
[View2 removeFromSuperview];
Your [self.view removeFromSuperview]
is actually removing whatever is at self.view
not the last subview you added.
You should be using [view2 removeFromSuperview]
instead.
精彩评论