PopModalAsync not working in iOs

Jerome Mx 21 Reputation points
2023-01-09T14:28:06.737+00:00

due to the limited control layout capabilities in ios via xamarin forms, i'm forced to use a modal form to to a some data entry, however I'm unable to remove the modal form Page as PopAsync fades the close button rather than than removing the modal!?. it looks like PopSync doesn't actually work as intended
I'm displaying the modal with:
Navigation.PushModalAsync(new addStaff());

and calling PopAsync like this:
var page = App.Current.MainPage.Navigation.PopModalAsync().Result;
I had to call it via App.Current otherwise I was getting: " PopAsync is not supported globally on iOS please use a NavifationPage"

to show what happens after PopAsync I've attached before and after screenshots:
277416-modal-page-before.png
277497-modal-page-after.png

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,272 questions
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 25,341 Reputation points Microsoft Vendor
    2023-01-10T06:42:28.997+00:00

    Hello,

    INavigation.PopModalAsync Method is an awaitable asynchronous method, you could not use xxx.PopModalAsync().Result, and you don't have to find the App.Current.MainPage.Navigation. As noted at the Xamarin.Forms Modal Pages doc : A NavigationPage instance is not required for performing modal page navigation.

    For example;

    Setting MainPage in App class:

     public App()
            {
                InitializeComponent();
               // MainPage = new NavigationPage(new MainPage());
                MainPage = new MainPage(); // the pop up and dissmiss appearance is same whether you set NavigationPage or not
            }
    

    Clicking button on MainPage to pop up the Page1(your addStaff page)

     private void Button_Clicked(object sender, EventArgs e)
            {
                Navigation.PushModalAsync(new Page1());
            }
    

    Dissmiss action on the Page1(your addStaff page)

     private void Button_Clicked(object sender, EventArgs e)
            {
                Navigation.PopModalAsync();
            }
    

    Best Regards, Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful