【问题标题】:Navigation in xamarin forms以 xamarin 形式导航
【发布时间】:2016-08-26 04:22:17
【问题描述】:

Xamarin 表单中的导航:我必须从页面 A 导航到页面 B。在页面 A 中,我写了 navigation.pushasync(new B)。当我从 B 页单击 popasync() 时,它会将我重定向到 A 页。这是正确的。

现在我在 A 中有另一个页面导航,即到页面 C。我也可以从 C 继续到 B。但是 B 的后退按钮应该总是回到 A。 当我从 C 转到 B 时,在单击 back(navigation.popasync()) 时,我到达的是 C,而不是 A。我不想创建 A ( navigation.pushasync(A)) 的新实例。我该如何解决这个问题?

简单来说,我如何从导航堆栈中弹出 2 个页面?

【问题讨论】:

  • 用段落格式化您的问题,以便用户正确阅读。

标签: c# ios xamarin xamarin.forms


【解决方案1】:
for (SecondViewController *controller in self.navigationController.viewControllers) {
    if ([controller isKindOfClass:[SecondViewController class]]) {
        [self.navigationController popViewControllerAnimated:YES];
        break;
    }else if ([controller isKindOfClass:[ThirdViewController class]]) {
        [self.navigationController popViewControllerAnimated:YES];
    }

}

【讨论】:

    【解决方案2】:

    使用navigation.pushasync(new B)会遇到这个问题

    我最好使用 Navigation.PushModalAsync(new B)。

    更多文档请阅读this:http://blog.adamkemp.com/2014/09/navigation-in-xamarinforms_2.html

    【讨论】:

      【解决方案3】:

      Navigation 对象有一个 NavigationStack 属性,它与浏览器历史记录基本相同。这是一个只读列表。所以你可以这样做。

      if (Navigation.NavigationStack[Navigation.NavigationStack - 2].GetType() == typeof(A))
          Navigation.PopAsync();
      Navigation.PopAsync();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-18
        • 1970-01-01
        相关资源
        最近更新 更多