akshay dilod
akshay dilod

Reputation: 131

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

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 provide a solution to this problem thanks in advance.

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

Here is the Xaml Code:

    <?xml version="1.0" encoding="utf-8"?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:NavTest" x:Class="NavTest.NavTestPage" Title="Home">
        <ContentPage.Content>
            <StackLayout Orientation="Vertical" VerticalOptions="Center">
                <Label Text="Welcome to Xamarin Forms!" VerticalOptions="Center" HorizontalOptions="Center" />
                <!--<Button Text="Go to " BackgroundColor="Lime" VerticalOptions="Center" Clicked="Handle_Clicked" >
            </Button>-->
                <ListView x:Name="myListView" ItemSelected="Handle_ItemSelected">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <Label Text="{Binding}" VerticalOptions="Center" HorizontalOptions="Center" />
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackLayout>
        </ContentPage.Content>
    </ContentPage>

Here's the OnClick Handler:

    async void Handle_Clicked(object sender, System.EventArgs e)
    {
        await  Navigation.PushAsync(new Page1());
    }                    

Upvotes: 10

Views: 13201

Answers (4)

Digvijay Rajput
Digvijay Rajput

Reputation: 351

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());

Upvotes: 1

Venkata Swamy Balaraju
Venkata Swamy Balaraju

Reputation: 1481

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

Upvotes: 20

Steven Thewissen
Steven Thewissen

Reputation: 2981

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();
}

Upvotes: 4

lowleetak
lowleetak

Reputation: 1382

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);
    }
}

Upvotes: 1

Related Questions