【问题标题】:want to use popViewControllerAnimated instead of popToRootViewControllerAnimated想使用 popViewControllerAnimated 而不是 popToRootViewControllerAnimated
【发布时间】:2010-09-07 09:48:02
【问题描述】:

我想使用 popViewControllerAnimated 而不是 popToRootViewControllerAnimated 来移动到根视图。我不想直接移动到根视图。那么有什么方法可以通过弹出所有以前的视图来移动到根视图?

【问题讨论】:

    标签: iphone cocoa-touch ipad ios


    【解决方案1】:

    据我所知,没有直接的方法可以做到这一点。

    你当然可以从调用-[UINavigationController popViewControllerAnimated:]UINavigationControllerDelegate 构建类似的东西,只要你没有到达堆栈的根,但这取决于你的堆栈增长的深度和你想要的频率如果您有这种行为,这可能会非常干扰您的用户。
    IE。他们什么也做不了,只能坐着看着视图飞过,而你一个又一个地弹出 NavigationController...

    编辑:
    抱歉回复晚了!
    所述委托协议定义了一个名为- navigationController:didShowViewController:animated: 的方法。如果您在具有属性的类中实现该协议,例如,shouldPopToRoot,您可以在触发弹出的操作中将其设置为 YES。
    所述方法可以遵循

    -(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
    {
        if ( self.shouldPopToRoot )
        {
            // Since this method gets called WHENEVER you pop a view-controller, you need
            // to ensure that you stop popping if you've just shown the root-view-controller
            if ( [navigationController.viewControllers itemAtIndex:0] == viewController )
                self.shouldPopToRoot = NO;
            else
                [navigationController popViewControllerAnimated:YES];
        }
    }
    

    【讨论】:

    • 你能举例解释一下吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-07
    • 2018-08-24
    • 1970-01-01
    • 2015-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多