3
votes

I am making an iOS app where I want to present a flow of pages like this:

Basically I want to achieve is to have this flow of pages:

PageA
PageB
PageC
PageD, dismiss back to:
PageC
PageD
PageE, dismiss back to:
PageA (starting point, start over again)

I am using ShowViewcontroller to present the pages (modal) and DismissViewcontroller to dismiss.

As per Apple's documentation if I dismiss a VC early in the stack all subsequent UIViewCOntroller are dismissed too (Apple doc).

However I experience that ViewWillAppear and ViewDidAppear are fired on the UIViewController that are dismissed even when they do not appear (e.g. in the example when dismissing back to PageA from PageE then ViewWillAppear is called on PageD, PageC, PageB too).

This does not seem logical to me. Can anyone explain why this is happening? And perhaps correct me if I am approaching this the wrong way.

I am using Xamarin.iOS.

Apple doc: If you present several view controllers in succession, thus building a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.

1
Is there any specific requirements to use modal ? I think you should use a navigation controller to get this flow. Modal is not used to navigate, it is something that pops up for some information.Sharon Nathaniel
@SharonNathaniel - no specific requirement. However I just used modal to avoid removing nav-bar etc (it should not be possible to navigate back). Actually the pages are not related. What idiom is normally used to navigate between non-related pages, with transitions but it should not be possible to navigate back etc.user2624732
You can use navigation controller, and hide back buttons on the specific view controllers on which you don't want users to go back. And when you want to go back to the root view controller just popToRootViewController.Sharon Nathaniel
I have this problem, too. My workaround is to use a flag to control this behavioronmyway133

1 Answers

1
votes

The ViewControllers work with a stack. Whenever a new ViewController (of any type) is added to the stack, You lose more and more control of your ViewControllers (especially when using a modal for your ViewControllers). So, say you have 5 ViewControllers in your stack (A, B, C, D, E, as per your example), and assume they are created in the order as stated, in order to return from ViewController E to ViewController A, you'd have to go through the entire stack. That means that every ViewController in your way needs to be displayed first, in order to dismiss is (since you already have ViewController E displayed, this doesn't occur here).

I hope this helps you. Good luck!

Love and regards, Björn