1
votes

The situation: I have an application entirely based on UInavigationcontroller. At some point in the application I push the controller A wich contains several subviews. Then i push a controller B which is an other new instance of the same class of controller A. Also controller B has some subviews.

When I pop controller B, the view associated to the controller A is shown. The problem is that on the screen there are also all the things of the view associated to controller B (over the subviews of A).

My guess is that somehow the problem is related to the fact that both controllers are instances of the same class. (With controller of different classes it works perfectly)

Thx.

Edit: All the stuff is done programmatically and with xib (no storyboard)

Push of view A:

ScreenViewController *secondView = [[ScreenViewController alloc] initWithNibName:@"ScreenViewController" bundle:nil];

// set some properties

[[self navigationController] pushViewController:secondView animated:YES];

Push of view B:

ScreenViewController *newScreenView = [[ScreenViewController alloc] initWithNibName:@"ScreenViewController" bundle:nil];

// set some properties

[[self navigationController] pushViewController:newScreenView animated:YES];

The view associated to the ScreenViewController contains a UIView (as a property) to wich I add all the subview that I need to display. I use a property and not directly the view because I need to put it into a UIScrollView.

1
More information required... post some code, maybe a storyboard pic...foundry

1 Answers

0
votes

I'm guessing you're using some code similar to:

[self.navigationController.view addSubview:mySubview];

I've dealt with this before by removing the subviews when the view is about to disappear:

- (void)viewWillDisappear:(BOOL)animated {

    [UIView animateWithDuration:0.3f
                          delay:0.0f 
                        options:UIViewAnimationOptionCurveEaseInOut 
                     animations:^(void){

                         mySubview.alpha = 0;

                     } 
                     completion:^(BOOL finished){

                         [mySubview removeFromSuperview];


      }];
    }

The above code will execute when you push or pop a new view controller, and it will 'fade out' the subview. When it's done, it removes it from the view. You just have to make sure that the subview gets re-added every time the view loads again. Hope this helps.