导航问题: 在iOS上不支持全局使用PopToRootAsync,请使用NavigationPage。

3
在App类中,我有以下内容:
MainPage = new NavigationPage(new MainPage());

在 MainPage 的 OnAppearing 事件中:
protected async override void OnAppearing ()
    {
        base.OnAppearing ();

        if (TempUserInfo.IsNewUser ())
            await this.Navigation.PushModalAsync ( new SignUpPage ());
    }

在用户输入所有信息后,在“注册页面”上使用以下内容:

在用户输入所有信息后,我使用以下代码:

await this.Navigation.PushModalAsync (new VerificationCodePage());

最后,在我检查验证页面上的验证码之后,我使用了以下代码:
await this.Navigation.PopToRootAsync ();

现在,我遇到了这个错误:

在iOS上全局不支持PopToRootAsync,请使用NavigationPage。

我想实现的正是上面的导航设置。


你认为我使用像MVVMLight这样的库会有帮助吗?我记得它有不同的导航选项。只是在思考... - abdul
你已经执行了2个PushModalAsync,所以需要执行2个PopModalAync,然后再执行PopToRootAsync。 - Jason
如果我从 VerificationPage 执行 PopModalAsync,它会将我发送回 SignUpPage!! 相反,我想弹出到主页面。 - abdul
这就是为什么你需要执行2个PopModals的原因。如果你不喜欢这样,那么重新设计你的导航。一种可能性是在你的App类中检测新用户,并直接导航到注册页面。一旦注册完成,不要导航到MainPage,而是完全替换App.MainPage。 - Jason
3个回答

1

而不是做

await this.Navigation.PopToRootAsync ();

您可以重置主页:

MainPage = new NavigationPage(new MainPage());

1
我采纳了Jason建议的导航方式,在VerificationPage页面中使用了以下代码:
MainPage = new NavigationPage(new MainPage());

感谢大家的帮助。


0

这个解决方案在Android上按照我的预期工作。将它们放在App.xaml.cs中。

 public static MyMasterDetail RootPage()
{
    return (MyMasterDetail)Current.MainPage;
}

public static void NavigateToHomePage()
{
    try
    {


        MainPage homePage = new MainPage();
        MyMasterDetail masterDetailRootPage = (MyMasterDetail)Application.Current.MainPage;
        masterDetailRootPage.Detail = new NavigationPage(homePage);
        masterDetailRootPage.IsPresented = false;

        Current.MainPage = masterDetailRootPage;
    }
    catch (Exception ex)
    {
        Debug.WriteLine("!!! NavigateToHomePage() Exception !!!");
        Debug.WriteLine("Exception Description: " + ex);
    }
}

然后你可以从任何地方调用回家的函数

   App.NavigateToHomePage();

或者显示主从左侧菜单

   App.RootPage().IsPresented = true;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接