【问题标题】:When using navigationpage's InsertPageBefore method toolbar items disappear on iOS当使用导航页的 InsertPageBefore 方法工具栏项目在 iOS 上消失
【发布时间】:2016-06-30 16:33:31
【问题描述】:

当我导航到使用 NavigationPage.Navigation.InsertPageBefore(ContentPage) 流的页面时,NavigationPage.PopAsync().ConfigureAwait(false) 全局导航页面上的工具栏项会消失,但使用推送/弹出工具时酒吧永远存在。这只发生在 iOS 上。

导航页面是应用程序级别的全局范围以及主详细信息页面,其中导航页面用作详细信息部分。

添加工具栏项

var toobaritemMenu = new ToolbarItem
 {
     Icon = "Screenshot",                                   
     Command = new Command(() => Device.BeginInvokeOnMainThread(() => App.MasterNavigation.PushAsync(new ContentPage(), false)))
 };
 App.MasterNavigation.ToolbarItems.Add(toobaritemMenu);

移动到这样的页面会导致工具栏项在 iOS 上消失

Device.BeginInvokeOnMainThread(() => App.MasterNavigation.Navigation.InsertPageBefore(new ContentPage(), App.MasterNavigation.CurrentPage));
Device.BeginInvokeOnMainThread(() => App.MasterNavigation.PopAsync().ConfigureAwait(false));

这是有原因的吗,因为它在 Android 上运行似乎不一致。

【问题讨论】:

    标签: xamarin xamarin.ios xamarin.forms


    【解决方案1】:

    我遇到了同样的问题。我的解决方法是改变我操作导航堆栈的方式:不是插入新页面并弹出当前页面,而是将新页面推送到堆栈上,然后删除当前页面:

    await currentPage.Navigation.PushAsync(nextPage, animated: true);
    currentPage.Navigation.RemovePage(currentPage);
    

    您最终会得到相同的最终导航堆栈,但它避免了导致 iOS 中辅助工具栏项目出现问题的任何问题。

    【讨论】:

    • 这救了我,因为我无法让 InsertPageBefore 在 iOS 上与堆栈保持一致。
    猜你喜欢
    • 1970-01-01
    • 2015-03-04
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多