【问题标题】:Continuously pushing view controllers不断推送视图控制器
【发布时间】:2012-08-07 08:13:44
【问题描述】:

我正在尝试制作一个导航控制器,当旋转到横向时,它会将新视图推送到堆栈上,当旋转回纵向时,它会弹出该视图。到目前为止,我可以显示横向视图,但只有当我可以通过将该视图控制器再次推入堆栈来恢复纵向视图时。我假设如果用户连续来回旋转,堆栈将耗尽内存。当我尝试使用 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];
    }
}

【问题讨论】:

    标签: iphone objective-c uiviewcontroller ios5.1


    【解决方案1】:

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

    【讨论】:

    • 好的。很酷,有效。我放置了 [delegate.navController popViewControllerAnimated:YES];在景观方法中,它起作用了。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-22
    • 2010-12-11
    • 1970-01-01
    • 2014-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多