PushAsync is not supported globally on iOS, please use a NavigationPage

前端 未结 4 1088
天命终不由人
天命终不由人 2021-01-05 03:47

Everything is working fine when I am handling the Tap event of a ListView item, but when I use this in a TabbedPage it shows the exception please p

相关标签:
4条回答
  • 2021-01-05 04:11

    You should put your TabbedPage child page into NavigationPage. The following is code snippets from Xamarin documentation.

    In Xaml:

    <TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            xmlns:local="clr-namespace:TabbedPageWithNavigationPage;assembly=TabbedPageWithNavigationPage"
            x:Class="TabbedPageWithNavigationPage.MainPage">
        <local:TodayPage />
        <NavigationPage Title="Schedule" Icon="schedule.png">
            <x:Arguments>
                <local:SchedulePage />
            </x:Arguments>
        </NavigationPage>
    </TabbedPage>
    

    Or In Code:

    public class MainPageCS : TabbedPage
    {
        public MainPageCS ()
        {
            var navigationPage = new NavigationPage (new SchedulePageCS ());
            navigationPage.Icon = "schedule.png";
            navigationPage.Title = "Schedule";
    
            Children.Add (new TodayPageCS ());
            Children.Add (navigationPage);
        }
    }
    
    0 讨论(0)
  • 2021-01-05 04:12

    In this error it goes and find the root page and if we are using Master detail page then we have to set the navigation for Detail page only. So following will be the best solution for this.

    ((RootPage)Application.Current.MainPage).Detail.Navigation.PushAsync(new SearchPage());
    
    0 讨论(0)
  • 2021-01-05 04:15

    This error will come while running in iOS only.

    In App.cs Rootpage(Start page) give like below

     public App()
      {
          MainPage=new NavigationPage(new LoginPage());
      }
    

    Now, We can use PushAsyn() in Globally

    0 讨论(0)
  • 2021-01-05 04:16

    You probably have some code somewhere similar to this in your App.xaml.cs:

    public App()
    {
        InitializeComponent();
    
        var tabs = new TabbedPage();    
        tabs.Children.Add(new NavTestPage() { Title = "Tab title" });
        MainPage = tabs;
    }
    

    Which you should change to:

    public App()
    {
        InitializeComponent();
    
        var tabs = new TabbedPage();
        var page = new NavTestPage() { Title = "Page title" };    
        tabs.Children.Add(new NavigationPage(page) { Title = "Tab title" });
    
        MainPage = tabs;
    }
    

    By wrapping in a NavigationPage you get the option to push pages onto the navigation stack. A TabbedPage on itself is just tabs with only 1 page per tab. This should give you a structure like this:

    TabbedPage
        NavigationPage
            ContentPage
        NavigationPage
            ContentPage
        NavigationPage
            ContentPage
    

    Update: I guess what you're doing is simply changing ContentPage to TabbedPage in your XAML. That's not how TabbedPage works. You should probably read up on how TabbedPage actually works in the first place.

    https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/navigation/tabbed-page/

    In your case you should probably create a new page which has XAML like this:

    <TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
                xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                xmlns:local="clr-namespace:NavTest"
                x:Class="NavTest.MyTabbedPage">
        <NavigationPage Title="NavTest">
            <x:Arguments>
                <local:NavTestPage />
            </x:Arguments>
        </NavigationPage>
    </TabbedPage>
    

    Set this as the MainPage in App.xaml.cs:

    public App()
    {
        InitializeComponent();
        MainPage = new MyTabbedPage();
    }
    
    0 讨论(0)
提交回复
热议问题