remove 2 subviews in one go.

Posted by Pavan on Stack Overflow See other posts from Stack Overflow or by Pavan
Published on 2011-01-08T15:45:57Z Indexed on 2011/01/08 15:54 UTC
Read the original article Hit count: 132

Filed under:
|
|
|
|

hi,

I am trying to remove two viewcontrollers (that have been added on top of each other) with one method. I have made the views in interfacebuilder. they all have their own .h and .m files to go with it.

Scenario I am in:

I have a main menu which has the view2 header file imported. In a method I add the second view on top of the superview like so

view2ViewController * view2 = [[view2ViewController alloc] initWithNibName:@"view2ViewController" bundle:nil];
[self.view addSubview:view2.view];

then in view 2 I have added the view 3 header file so i can add view 3 as a subview ontop of view2. i have another method which is connected again to interface builder to a UIButton so upon button press a method gets called in view2 which adds view 3 on top in exactly the same way like so:

view3ViewController * view3 = [[view3ViewController alloc] initWithNibName:@"view3ViewController" bundle:nil];
[self.view addSubview:view3.view];

What im trying to solve: I have a button in view 3 which should remove view 3.... and then it should also remove view 2 aswell so the main screen is visible.

How can this be achieved?

What I have so far:

[self.view removeFromSuperview];

This however only removes View 3... but leaves view 2 in place.

What needs to be modified so that i can remove view 2 as well??

Any help is appreciated.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c