Issue
I have a xamarin.forms app which have a navigation like this.
MainPage -->(PushmodelASync) Second Page-->(PushModelAsync)--> Third page
What I am trying to do is when navigating from Second Page to Third Page I need to Popmodelasync the second page. To do this I called PopmodelAsync in OnDissappearing. In android it works fine . But in iOS what happens is the third page will open and close instead of closing of second page
protected async override void OnDisappearing()
{
base.OnDisappearing();
await Navigation.PopModalAsync();
}
How to solve this? Any help is appreciated.
Solution
You could change their order when invoking Push and Pop.
In the current scene, we should better pop the current page first, then push to next page. Maybe calling them in reverse order will work in Android, however it not works in iOS. Because when invoking OnDisappearing method, app will miss the isntance of PageSecond in iOS. Therefore, PopModalAsync will has no effect. We can call pop first, and then call push method to make it works.
For example, in the PageSecond.cs:
public partial class PageSecond : ContentPage
{
public PageSecond()
{
InitializeComponent();
}
private async void Button_Clicked(object sender, EventArgs e)
{
await Navigation.PopModalAsync();
}
protected override async void OnDisappearing()
{
base.OnDisappearing();
await Navigation.PushModalAsync(new PageThird());
}
}
The needed effect will show in iOS:
And effect in android:
Answered By - Junior Jiang


0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.