I have three UIViewControllers that I need to show in succession. The UIViewController1 is my main view controller and has a button. Clicking on the button displays UIViewController2 modally. After 30 seconds, UIViewController3 is automatially shown modally. Do I have to first dimiss UIViewcontroller2 and then display UIViewController3?. I have a Done button on UIViewcontroller3 and clicking on it should take me back to UIViewController1 (main view controller). Do I have first dismiss UIViewController2 from the chain and then do a alloc/init on UIViewController1 to show it?. I don't want to get any memory leaks in this process.
Please help.
There are two main ways that you can do this, one of which, you have alluded to. After testing this scenario in XCode.
The first involves dismissing all modal view controllers from the final view controller (the third). By doing this, you cannot use animation to dismiss the view controllers. If you try to animate them, the second will not be dismissed. (Granted, you could dismiss the second one with animation, but it would display the animation from the second to the first, rather than from the third to the first)
To do this, you'll need to pass your second view controller as a property to your third view controller so you can call the line:
Note that parentVC is a property that should be set to point to the second view controller
Then when dismissing:
This will take you back to the first view controller.
The second, which is not really better or worse, but is probably easier to code, is to dismiss the second view controller before going to the third; again, you probably will not want to animate the view controllers between the transition from the second to the third, but you could animate from the third to the first.