首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取"PushAsync在iOS上不支持全局.“在使用NavigationPage时

获取"PushAsync在iOS上不支持全局.“在使用NavigationPage时
EN

Stack Overflow用户
提问于 2017-08-05 16:56:25
回答 1查看 1K关注 0票数 4

艾略尔,我一直得到以下信息:

System.InvalidOperationException with "PushAsync在iOS上不支持全局,请使用NavigationPage“

尽管我使用的是一个NavigationPage,而且从我所能知道的情况来看,我正在正确地使用它。我的F#技能并不令人惊讶,所以我肯定认为我在这里做错了什么,但令人惊讶的是,在F#中很难找到预生成Navigation.PushAsync的例子。我确实找到了这段代码,并一直在寻找一个正确外观的例子。

https://github.com/fsprojects/Tamarin/blob/master/samples/Todo/TodoListMvc.fs

在这个示例中,我看到了包装在async{}中的代码

代码语言:javascript
复制
 do! this.Navigation.PushAsync(page = downcast view.Root) |> Async.AwaitIAsyncResult |> Async.Ignore

所以我想我离这里不远了。这么说,我做错什么了?

AssemblyVersions

  • Xamarin.Forms版本2.3.5.256-pre6
  • FSharp.Core版本4.0.0.1

代码

代码语言:javascript
复制
namespace Eclipsefest

open System
open Xamarin.Forms
open Xamarin.Forms.Xaml

type MenuItem = 
{ Title : string
  TargetType : System.Type }

type MenuPage() = 
inherit ContentPage()
let _ = base.LoadFromXaml(typeof<MenuPage>)
member this.Handle_Tapped(sender : Object, arg : EventArgs) = 
    let navItem = sender :?> TextCell
    async { 
        match navItem.Text with
        | "Information" -> 
            do! this.Navigation.PushAsync(page = new NavigationPage(new InfoPage()))
                |> Async.AwaitIAsyncResult
                |> Async.Ignore
        | "Events" -> 
            do! this.Navigation.PushAsync(new NavigationPage(new EventsPage()))
                |> Async.AwaitIAsyncResult
                |> Async.Ignore
        | "BusRoute" -> 
            do! this.Navigation.PushAsync(new NavigationPage(new BusRoutePage()))
                |> Async.AwaitIAsyncResult
                |> Async.Ignore
        | "Glasses" -> 
            do! this.Navigation.PushAsync(new NavigationPage(new GlassesPage()))
                |> Async.AwaitIAsyncResult
                |> Async.Ignore
        | "Merch" -> 
            do! this.Navigation.PushAsync(new NavigationPage(new MerchPage()))
                |> Async.AwaitIAsyncResult
                |> Async.Ignore
        | "Day" -> 
            do! this.Navigation.PushAsync(new NavigationPage(new DayPage()))
                |> Async.AwaitIAsyncResult
                |> Async.Ignore
        | "About" -> 
            do! this.Navigation.PushAsync(new NavigationPage(new AboutPage()))
                |> Async.AwaitIAsyncResult
                |> Async.Ignore
        | _ -> 
            do! this.Navigation.PushAsync(new NavigationPage(new EclipsefestPage()))
                |> Async.AwaitIAsyncResult
                |> Async.Ignore
    }
    |> Async.RunSynchronously

代码更新

代码语言:javascript
复制
open System
open Xamarin.Forms
open Xamarin.Forms.Xaml

type MenuItem = 
    { Title : string
      TargetType : System.Type }

type MenuPage() = 
    inherit ContentPage()
    let _ = base.LoadFromXaml(typeof<MenuPage>)
    member this.Handle_Tapped(sender : Object, arg : EventArgs) = 
        this.Navigation.PushAsync(new NavigationPage(new EclipsefestPage())) |> ignore

我也尝试过这一点,并收到了同样的错误。我怀疑我的问题在于异步部分,但它似乎也抛出了相同的异常而没有异步。

代码更新2

代码语言:javascript
复制
open System
open Xamarin.Forms
open Xamarin.Forms.Xaml

type MenuItem = 
    { Title : string
      TargetType : System.Type }

type MenuPage() = 
    inherit ContentPage()
    let _ = base.LoadFromXaml(typeof<MenuPage>)
    member this.Handle_Tapped(sender : Object, arg : EventArgs) = 
        let page = new EclipsefestPage()
        let navpage = new NavigationPage(page)
        let result = this.Navigation.PushAsync(navpage)
        result.RunSynchronously()

我开始觉得这是个窃听器。我已经验证了在调用Navigation.PushAsync之前,页面和导航页是在单独的步骤中实例化的,并且仍然得到相同的异常。

错误

"PushAsync在iOS上不受全局支持,请使用NavigationPage。“

StackTrace

代码语言:javascript
复制
System.InvalidOperationException: PushAsync is not supported globally on iOS, please use a NavigationPage.
  at Xamarin.Forms.Platform.iOS.Platform.Xamarin.Forms.INavigation.PushAsync (Xamarin.Forms.Page root, System.Boolean animated) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Platform.cs:154
  at Xamarin.Forms.NavigationProxy.OnPushAsync (Xamarin.Forms.Page page, System.Boolean animated) [0x00022] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\NavigationProxy.cs:190
  at Xamarin.Forms.NavigationProxy.PushAsync (Xamarin.Forms.Page root, System.Boolean animated) [0x00013] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\NavigationProxy.cs:109
  at Xamarin.Forms.NavigationProxy.OnPushAsync (Xamarin.Forms.Page page, System.Boolean animated) [0x00022] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\NavigationProxy.cs:190
  at Xamarin.Forms.NavigationProxy.PushAsync (Xamarin.Forms.Page root, System.Boolean animated) [0x00013] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\NavigationProxy.cs:109
  at Xamarin.Forms.NavigationProxy.OnPushAsync (Xamarin.Forms.Page page, System.Boolean animated) [0x00022] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\NavigationProxy.cs:190
  at Xamarin.Forms.NavigationProxy.PushAsync (Xamarin.Forms.Page root, System.Boolean animated) [0x00013] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\NavigationProxy.cs:109
  at Xamarin.Forms.NavigationProxy.PushAsync (Xamarin.Forms.Page root) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\NavigationProxy.cs:102
  at <StartupCode$Eclipsefest>.$MenuPage.xaml+Handle_Tapped@17.Invoke (Microsoft.FSharp.Core.Unit unitVar) [0x00090] in /Users/terrancesmith/Projects/Eclipsefest/Eclipsefest/MenuPage.xaml.fs:19
  at Microsoft.FSharp.Control.AsyncBuilderImpl+callA@851[b,a].Invoke (Microsoft.FSharp.Control.AsyncParams`1[T] args) [0x00047] in <5584acdb904cf4daa7450383dbac8455>:0
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.36/src/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:151
  at Microsoft.FSharp.Control.AsyncBuilderImpl.commit[a] (Microsoft.FSharp.Control.AsyncBuilderImpl+Result`1[T] res) [0x00030] in <5584acdb904cf4daa7450383dbac8455>:0
  at Microsoft.FSharp.Control.CancellationTokenOps.RunSynchronously[a] (System.Threading.CancellationToken token, Microsoft.FSharp.Control.FSharpAsync`1[T] computation, Microsoft.FSharp.Core.FSharpOption`1[T] timeout) [0x000a3] in <5584acdb904cf4daa7450383dbac8455>:0
  at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[T] (Microsoft.FSharp.Control.FSharpAsync`1[T] computation, Microsoft.FSharp.Core.FSharpOption`1[T] timeout, Microsoft.FSharp.Core.FSharpOption`1[T] cancellationToken) [0x00071] in <5584acdb904cf4daa7450383dbac8455>:0
  at Eclipsefest.MenuPage.Handle_Tapped (System.Object sender, System.EventArgs arg) [0x00008] in /Users/terrancesmith/Projects/Eclipsefest/Eclipsefest/MenuPage.xaml.fs:16
  at Xamarin.Forms.Cell.OnTapped () [0x00008] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Cells\Cell.cs:106
  at Xamarin.Forms.TextCell.OnTapped () [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Cells\TextCell.cs:82
  at Xamarin.Forms.TableView+TableSectionModel.OnRowSelected (System.Object item) [0x00007] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\TableView.cs:214
  at Xamarin.Forms.TableModel.RowSelected (System.Object item) [0x0001a] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\TableModel.cs:65
  at Xamarin.Forms.TableModel.RowSelected (System.Int32 section, System.Int32 row) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\TableModel.cs:57
  at Xamarin.Forms.Platform.iOS.TableViewModelRenderer.RowSelected (UIKit.UITableView tableView, Foundation.NSIndexPath indexPath) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Renderers\TableViewModelRenderer.cs:85
  at at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/data/lanes/4691/d2270eec/source/xamarin-macios/src/UIKit/UIApplication.cs:79
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/4691/d2270eec/source/xamarin-macios/src/UIKit/UIApplication.cs:63
  at Eclipsefest.iOS.Main.main (System.String[] args) [0x00001] in <59853c0a6da8a60ca74503830a3c8559>:0
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-14 21:21:57

来自Xamarin的人的回答。

在您显示的代码中,您正在包装要在NavigationPage中推送的新页面。但是,您正在推送的页面需要在导航页中。 最简单的方法是将初始页面包装在NavigationPage中,然后将其设置为MainPage。然后,只需直接推送新页面,而不将它们包装在另一个NavigationPage中,因为这样做会导致其他问题。看看这个:

https://gist.github.com/jimmgarrido/d0b702c1282faa5bb91d0ed14e2d7e1b

代码语言:javascript
复制
namespace FForms

open System
open Xamarin.Forms

type TestPage() as this = 
    inherit ContentPage()

    let nextBtn = Button(Text = "Next Page")
    let layout = StackLayout()

    let handler = EventHandler(fun sender args ->
        let newPage = ContentPage(BackgroundColor = Color.Red)
        do this.Navigation.PushAsync(newPage))

    do nextBtn.Clicked.AddHandler handler
    do layout.Children.Add nextBtn
    do base.Content <- layout

type App() = 
    inherit Application(MainPage = NavigationPage(TestPage()))

希望这能有所帮助!

它做了~

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45524358

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档