Hersha
Hersha

Reputation: 207

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 addSubview: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?

Upvotes: 0

Views: 3352

Answers (2)

Rog
Rog

Reputation: 18670

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.

Upvotes: 2

Alan Zeino
Alan Zeino

Reputation: 4396

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];

Upvotes: 2

Related Questions