5

I am trying to understand modal vs push segue and read few Q & A like this and this. One point I am confused from these answers is "The presenter should take care of dismissing the VC it presented."

For example, the example I am writing shows UIPageViewController something like the example available here, with a button at bottom of the page with name "Skip".

In story board I have created a segue (of type Modal) from "Skip" button to another "View Controller" (let us say LoginViewController), but where do I need to dismiss the UIPageViewContoller (if at all required) and how?

EDIT: After little bit more reading, it seems UIPageViewController (Which has Skip button) should take care of dismissing LoginViewController (because UIPageViewController is the presenter).

In my case, after Login complete, I would like to navigate to "Menu" page, then how can I ask UIPageViewController to dismiss the "LoginViewController" and move to MenuController? I couldn't find any example on how this works.Any help would be appreciated!

Community
  • 1
  • 1
kosa
  • 65,990
  • 13
  • 130
  • 167
  • 1
    Hi, if you know about EXIT feature in storyboard , you can try that. http://stackoverflow.com/questions/12561735/what-are-unwind-segues-for-and-how-do-you-use-them – Deepak Dec 30 '14 at 06:43
  • I have some idea about EXIT, but could you please explain little bit more on how I could use it in this case? – kosa Dec 30 '14 at 06:46
  • actually i am not sure it will work or not but using EXIT feature you can first dismiss the UIPageViewController and then from the parent controller of UIPageViewController you can call LoginViewController. – Deepak Dec 30 '14 at 06:48
  • AFAIK, exit will be linked to one of the unwind methods in parent controller. Will wait and see if any experts can chime in to help me. Thank you for your time! – kosa Dec 30 '14 at 06:51
  • yes inside those unwind methods in parent you can call LoginViewController. For this i know you have to change a little bit of storyboard design but it should work. – Deepak Dec 30 '14 at 06:53

2 Answers2

5

As per the tutorial link you have given in question.

There is a APPViewController which is root for the UIPageViewController and also in AppDelegate, so on top of that view, require a Skip button which is above all the subViews in AppViewController. So its IBAction event will be in AppViewController only.

Now first change your AppDelegate self.window.rootViewController to LoginViewController. In LoginViewController viewDidLoad event, presentModal UIPageViewController.

Now in its action event of skip button, you can write like this:

[self dismissViewControllerAnimated:YES completion:nil];

So it will automatically dismiss all your AppChildViewControllers, and will display LoginViewController, which is already behind.

This is just a base logic to achieve your goal, you might require to change code as per your project implementation.

Hope this helps.

Mrunal
  • 13,982
  • 6
  • 52
  • 96
  • Thank you! Will try it tomorrow. – kosa Dec 30 '14 at 15:22
  • I opted for "push" instead of "modal" because of few flow changes. But I think your answer will be the solution if we use "modal". I am accepting your answer. – kosa Jan 02 '15 at 15:26
0

First dismiss the UIPageViewController and then using delegate or block methods (whatever suitable) to get notified when you press the skip button in the parent controller and then calling LoginViewController.

Deepak
  • 348
  • 4
  • 14