从堆栈中删除 ViewController [英] Remove ViewController from stack

查看:35
本文介绍了从堆栈中删除 ViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的应用程序中,我们有一个登录ViewController A.在用户登录时,会自动调用导航请求以导航到下一个 ViewController B.但是,当这完成后,我们想从堆栈中删除登录 ViewController A,这样用户就不能返回"到登录视图,而是返回之前的 ViewController 代替登录.

In our App we have a log-in ViewController A. On user log-in, a request navigate is automatically called to navigate to the next ViewController B. However when this is done we want to remove the log-in ViewController A from the stack so the user cannot "go back" to the log-in view but goes back the previous ViewController before the log-in instead.

我们考虑过在加载 ViewController B 时将 ViewController A 从堆栈中移除,但有没有更好的方法?

We thought about removing the ViewController A from the stack when ViewController B is loaded, but is there a better way?

在应用程序的 Android 版本中,我们设置了 history=no(如果我没记错的话)然后它就可以工作了.

In the Android version of the App we've set history=no (if I recall correctly) and then it works.

在 MonoTouch 和 MvvmCross 中是否有类似的方法来实现这一点?

Is there an similar way to achieve this in MonoTouch and MvvmCross?

推荐答案

我最终从导航控制器中删除了不需要的视图控制器.在我登录的 ViewDidDisappear()ViewController 我做了以下事情:

I ended up with removing the unwanted viewcontroller from the navigation controller. In ViewDidDisappear() of my login ViewController I did the following:

public override void ViewDidDisappear (bool animated)
{
    if (this.NavigationController != null) {
        var controllers = this.NavigationController.ViewControllers;
        var newcontrollers = new UIViewController[controllers.Length - 1];
        int index = 0;
        foreach (var item in controllers) {
            if (item != this) {
                newcontrollers [index] = item;
                index++;
            }

        }
        this.NavigationController.ViewControllers = newcontrollers;
    }
    base.ViewDidDisappear(animated);
}

这样我就可以在从视图中删除不需要的 ViewController 时删除它.我不完全相信这是否是正确的方法,但它工作得相当好.

This way I way remove the unwanted ViewController when it is removed from the view. I am not fully convinced if it is the right way, but it is working rather good.

这篇关于从堆栈中删除 ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆