0

我正在尝试制作一个导航控制器,当旋转到横向时,它会将新视图推送到堆栈上,当旋转回纵向时,它会弹出该视图。到目前为止,我可以显示横向视图,但只有当我可以通过将该视图控制器再次推送到堆栈上来恢复纵向视图时。我假设如果用户连续来回旋转,堆栈将耗尽内存。当我尝试使用 popToViewController 时,没有任何反应。有人可以帮我让 pop 功能正常工作吗?

此方法在我的 ViewController 类中:

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

此方法在我的 Landscape 类中:

-(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];
    }
}
4

1 回答 1

1

[delegate.navController popViewControllerAnimated:YES];看来您的 ViewController 应该已经在堆栈上,因此您应该能够通过调用而不是调用来取回它[delegate.navController pushViewController:viewController animated:YES];

于 2012-08-07T00:13:44.827 回答