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

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

问题描述

在我们的应用中,我们具有登录ViewController A.在用户登录时,将自动调用一个请求导航,以导航到下一个ViewController B.但是,完成此操作后,我们希望从堆栈中删除登录ViewController A,以使用户无法返回"登录视图,而是返回登录之前的前一个ViewController.

我们曾考虑在加载ViewController B时从堆栈中删除ViewController A,但是有更好的方法吗?

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

在MonoTouch和MvvmCross中是否有类似的方法来实现此目的?

解决方案

我最终从导航控制器中删除了不需要的viewcontroller.在我的登录名ViewControllerViewDidDisappear()中,我执行了以下操作:

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时,我就将其删除了.我不完全相信这是正确的方法,但是效果很好.

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.

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

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

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

解决方案

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);
}

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天全站免登陆