Link representing view controller from modal (objective-c)
I have a navigation stack consisting of:
UINavigationViewController
-> WelcomeViewController
-> RoleViewController
I would like to add a modal viewcontroller between Welcome and Role. I add ModalViewController via storyboard and assign Segue (Present Modally) to ModalViewController via button in WelcomeViewController. This is all good and the modal shows are great.
Now that I am inside the ModalViewController , I would like to dismiss the modal and perform the original segue from Welcome to Role. I did several searches on StackOverflow and came up with different ideas on how to do this. The most logical way was outlined here: Dismissviewcontroller and execute segue
UIViewController *parentController = self.presentingViewController;
[self dismissViewControllerAnimated:YES completion:^(void){
[parentController performSegueWithIdentifier:@"segue_gotoRole" sender:self];
}];
The modal is rejected, but the segue is not executed and the application crashes:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Receiver (<NavigationViewController: 0x78b96b80>) has no segue
with identifier 'segueToRole''
So self.presentingViewController targets the UINavigationViewController, not the WelcomeViewController, which actually represents the modal. To be successful I need to find a way to get the view controller of the view that is defined in the storyboard as the segue creator from the modal .
I've tried many different combinations for example. self.parentViewController, self.presentationViewController, I even tried to loop through the navigation stack to highlight the WelcomeViewController and set it up as an object to do the segue, but nothing works.
Please help me.:)
source to share
What I did was send the host's link to the submitted instance.
This can be accomplished by setting the class reference view property on the presented class.
For example,
@property (strong, nonatomic) PresentingClass *presenter;
...
Then in the implementation of the view class
presentedClass.presenter = self;
[self presentViewController:presentedClass animated:YES completion:nil];
Finally, in the provided implementation, just call
if(presenter){
[presenter foo];
}
May I help. Let me know.
source to share