问题描述
我有一个xamarin.forms应用,该应用具有这样的导航。
MainPage -->(PushmodelASync) Second Page-->(PushModelAsync)--> Third page
我想做的是从Second Page
导航到Third Page
时,我需要Popmodelasync第二页。为此,我在Ondissappearing
中调用了PopmodelAsync。在android上可以正常工作。但是在iOS中,发生的情况是第三页将打开和关闭,而不是第二页关闭
protected async override void Ondisappearing()
{
base.Ondisappearing();
await Navigation.PopModalAsync();
}
如何解决?任何帮助表示赞赏。
解决方法
您可以在调用Push
和Pop
时更改其顺序。
在当前场景中,我们最好先弹出当前页面,然后再推送到下一页。也许以相反的顺序调用它们将在Android中工作,但是在iOS中则行不通。因为在调用OnDisappearing
方法时,应用程序会错过iOS中PageSecond
的含义。因此,PopModalAsync
将无效。我们可以先调用pop
,然后调用push
方法使其生效。
例如,在 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());
}
}
所需的效果将在iOS中显示:
并在android中起作用: