I have a first view which is the log in screen. After the user logs in there’s a button to push the view to my second view. My problem is that when I press the button which pushes back to the first view, it calls the viewDidLoad method and runs the view as though I just built the app. I have other labels that are set according to the logged in user, so I want to have my state of the first view before it was pushed to be retained.
This is the method I use to push to second view:
-(IBAction) secondView
{
_secondView = [[SecondViewController alloc]initWithNibName:nil bundle:nil];
[self presentModalViewController:_secondView animated:YES];
[_secondView release];
}
and the method to push back to first view:
-(IBAction) back {
_firstView = [[FirstViewController alloc]initWithNibName:nil bundle:nil];
[self presentModalViewController:_firstView animated:YES];
[_firstView release];
}
I’m not using navigation controller, so is there a way to push back to my first view to the way it is when I pushed to my second view? Thanks in advance.
To go back to the firstViewController, instead of pushing it onto the stack (which would then be
_firstView _secondView _firstView), pop the secondViewController withThe problem with what you’re doing is that you are creating a new firstViewController when you “go back” using your current method (
allocandinitare the clues to this). Really, you just want to pop the secondViewController off of the top of the firstViewController, which you can do with the method above.