OGeek|极客世界-中国程序员成长平台

标题: ios - 从堆栈中弹出当前 View 并推送新的 Xamarin [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 11:31
标题: ios - 从堆栈中弹出当前 View 并推送新的 Xamarin

我有一个应用程序,我在注册表单中,当用户单击提交时,它会将他们带到上一页。在上一页时,如果用户单击返回,则会将他们带回我不想要的注册页面。如何从堆栈中删除该注册 View ?

这是我目前的做法:

//inside MyRegistrationController button press
MyPreviousController SVC = this.Storyboard.InstantiateViewController("MyPreviousController") as MyPreviousController;
            if(SVC != null){
                SVC.offender = offender;


                //var viewControllers = this.NavigationController.ViewControllers;
                //viewControllers[viewControllers.Length - 1].View.RemoveFromSuperview();
                //this.NavigationController.ViewControllers = viewControllers;

                this.NavigationController.PopViewController(true);
                this.NavigationController.PushViewController(SVC, true);
            }

当前的方法对堆栈做了一些奇怪的事情,我单击 MyRegistrationController 上的按钮我转到 MyPreviousController(未更新)然后快速转到更新版本MyPreviousController 回到 MyPreviousController 的更新版本,然后如果我单击后退按钮,我会返回 MyPreviousController



Best Answer-推荐答案


好的,我最终让它工作了。我的问题最终是双重的。一是我需要弹出 View ,二是我需要重新加载 MyPreviousController 中的表数据(我没有提出的问题)。所以我需要做以下事情:

要简单地弹出当前 Controller ,我只需要说:

//inside MyRegistrationController button press
MyPreviousController SVC = this.Storyboard.InstantiateViewController("MyPreviousController") as MyPreviousController;
        if(SVC != null){
            SVC.offender = offender;

            this.NavigationController.PopViewController(true);
}

但是,这样做会导致我在 MyPrevious 中的表格无法更新。所以我需要把它放在 MyPreviousController.cs:

public override void ViewWillAppear (bool animated)
    {
        base.ViewWillAppear (animated);
        InvokeOnMainThread (delegate {
            TableView.Source = source;
            TableView.ReloadData();
        });
    }

并且成功更新了表格并移除了注册 View

关于ios - 从堆栈中弹出当前 View 并推送新的 Xamarin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37550852/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4