I'm trying to make a navigation controller that when rotated to landscape pushes a new view onto the stack and when rotated back to portrait it pops that view. So far I can get the landscape view displayed, but the only when I can get the portrait back by pushing that view controller again onto the stack. I assume that the stack will run out of memory if a user continuously rotates back and forth. When I tried using the popToViewController, nothing happens. Can someone help me get the pop function working?
This method is in my ViewController class:
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
AppDelegate *delegate =
(AppDelegate *)[[UIApplication sharedApplication] delegate];
Landscape *landScape=
[[Landscape alloc] initWithNibName:@"Landscape" bundle:nil];
[delegate.navController pushViewController:landScape animated:YES];
}
}
This method is in my Landscape class:
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if(toInterfaceOrientation == UIInterfaceOrientationPortrait ||
toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
AppDelegate *delegate =
(AppDelegate *)[[UIApplication sharedApplication] delegate];
ViewController *viewController=
[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
[delegate.navController pushViewController:viewController animated:YES];
}
}