3
votes

I have a navigation stack consisting of:

UINavigationViewController
 -> WelcomeViewController
 -> RoleViewController

I would like to add a modal viewcontroller in between Welcome and Role. I add a ModalViewController via storyboard and assign a segue (Present Modally) to the ModalViewController from a button in WelcomeViewController. It's all good and the modal shows up fine.

Now that I'm inside the ModalViewController I would like to dismiss the modal and perform the original segue from Welcome to Role. I did some searching on StackOverflow and came over different takes on how to do this. The most logical way was set out here: Dismissviewcontroller and perform segue

UIViewController *parentController = self.presentingViewController;
[self dismissViewControllerAnimated:YES completion:^(void){
    [parentController performSegueWithIdentifier:@"segue_gotoRole" sender:self];
}];    

The modal is dismissed but the segue is not executed and the app crashes:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Receiver (<NavigationViewController: 0x78b96b80>) has no segue
with identifier 'segueToRole''

So the self.presentingViewController targets the UINavigationViewController and not the view controller WelcomeViewController which is actually presenting the modal. To succeed I need to find a way to get the presenting view controller which is defined in the storyboard as the segue originator from within the modal.

I've tried a lot of different combinations, e.g. self.parentViewController, self.presentationViewController, I've even tried to loop through the navigation stack to single out the WelcomeViewController and target it specifically as the object to perform the segue, but nothing seems to work.

Please help me. :)

2
Do you present your view controller from navigation controller or WelcomeViewController ?Ozgur Vatansever
The modal is executed when pressing the button in the WelcomeViewController (which is embedded in the NavigationViewController).Anders Holm-Jensen

2 Answers

1
votes

If it were me, I'd write a delegate protocolhere in Modal VC that you're presenting and make WelcomeViewController the delegate - Once its dismissed, the WelcomeViewController can take over and segue to RoleViewController ?

0
votes

What I did is to send the presenter reference to the presented instance.

This can be implemented by setting up a property of presenting class reference in the presented class.

For example,

@property (strong, nonatomic) PresentingClass *presenter;

.

Then, in the presenting class implementation

presentedClass.presenter = self;
[self presentViewController:presentedClass animated:YES completion:nil];

Finally, in the presented implementation, simply call

if(presenter){
  [presenter foo];
}

Could help. Let me know.