NavigationStack is not updated successfully in xamarin forms ios

I have a xamarin forms project and i use custom master detail page. so i have MasterDetailPage and NavigationPageRenderer in xamarin ios and xamarin android project. i want to navigate as follows

var mdp = App.Current.MainPage as MasterDetailPage;
await mdp.Detail.Navigation.PushAsync(new Page1());
await mdp.Detail.Navigation.PushAsync(new Page2());
await mdp.Detail.Navigation.PushAsync(new Page3());
await mdp.Detail.Navigation.PushAsync(new Page4());
await mdp.Detail.Navigation.PushAsync(new Page5());
await mdp.Detail.Navigation.PushAsync(new Page6());

i have a NavigationStack of 6 elements and i want to go Page2 from Page6. So I did the following operations
for (int i = 0; i < 3; i++)
{
mdp.Detail.Navigation.RemovePage(mdp.Detail.Navigation.NavigationStack[mdp.Detail.Navigation.NavigationStack.Count - 2]);
}
await mdp.Detail.Navigation.PopAsync();

i remove pages between Page6 and Page 2 and then i remove last page(Page6) with PopAsync. This worked successfully in android project. But it's not working in ios project. The stack successfully changed in the ios project, but view is not updated successfully. The screen appears as the title of page 6 and white screen. Page2 doesn't appear.

I tried the following
Device.BeginInvokeOnMainThread(async () => await mdp.Detail.Navigation.PopAsync());
and
await mdp.Detail.Navigation.PopAsync(true);

But it's not working.

Who can help me with this problem?

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭
    for (int i = 0; i < 3; i++)
    {
    mdp.Detail.Navigation.RemovePage(mdp.Detail.Navigation.NavigationStack[mdp.Detail.Navigation.NavigationStack.Count - 2]);
    }
    

    Stop. You don't want to move forward through a collection and then remove things from the collection, then increment your movement. That causes skipping.

    Follow me

    1
    2 - Index
    3
    4
    5

    When you remove item 3.. 4 becomes 3... 5 becomes 4... and so on
    Now you move your index to 3... but that's the old 4... meaning you have just leapfrogged over the old 3.

    If you are moving forward while removing you have to deliberately decrement your counter index so you keep removing at the same point until your final condition is met. OR work backwards and not cause a lot of movement.
    Remove 5, then 4, then 3, then 2 {...}

  • pelinalpppelinalpp Member ✭✭

    I didn't understand what you said. Actually I have a structure in which I navigate files.
    What I want to do is, for example:
    when i am in page2, I press a button called move and I want to move called x file on the page2. To do this, i go to the move page (MovePage1). And I'm going to the page I want to move (so in order: MovePage1->MovePage2->MovePage3->MovePage4)

    So what I'm actually doing is
    await mdp.Detail.Navigation.PushAsync(new Page1());
    await mdp.Detail.Navigation.PushAsync(new Page2());
    await mdp.Detail.Navigation.PushAsync(new MovePage1());
    await mdp.Detail.Navigation.PushAsync(new MovePage2());
    await mdp.Detail.Navigation.PushAsync(new MovePage3());
    await mdp.Detail.Navigation.PushAsync(new MovePage4());

    when I arrive the page I want, i click complete button. And I want to go back page2 and I continue to navigate from where I stayed.
    for this I did this
    for (int i = 0; i < 3; i++)
    {
    mdp.Detail.Navigation.RemovePage(mdp.Detail.Navigation.NavigationStack[mdp.Detail.Navigation.NavigationStack.Count - 2]);
    }
    await mdp.Detail.Navigation.PopAsync();

    so i did know this. i removed MovePage3 and i put MovePage4 instead of MovePage3.
    After for loop, I have a stack in Page1, Page2 and MovePage4

    And then i did pop and i have Page1 and Page2. so i went to back Page2

    Actually i < 3 is not a fixed value. I asked this way to explain my problem. i < (Count of page that i went to movepage - 1)
    You mean what you're doing is wrong? So what should I do for this?

  • LandLuLandLu Member, Xamarin Team Xamurai

    @pelinalpp I create a blank master detail page, but I can't reproduce your issues using your pop code. I can successfully reach the page 2 from page 6. And It seems there's nothing wrong in your code.
    Could you please share a sample? It can help us find out what your error really is.

  • pelinalpppelinalpp Member ✭✭
    Thank you for answer. Did you try it on xamarin forms ios platform? Cause on android it works well. Actually pops also work on ios but the page view is not refreshed after popasync. Instead i see only blank screen not the page2.
  • LandLuLandLu Member, Xamarin Team Xamurai

    Yes, I tried but I can't reproduce that. So if you could share your sample, we can figure out what happened there.

Sign In or Register to comment.