I am facing a problem while trying to unwind using a custom segue from a view controller that was added as a child to another view controller.
Here is MyCustomSegue.m:
- (void)perform
{
if (_isPresenting)
{
//Present
FirstVC *fromVC = self.sourceViewController;
SecondVC *toVC = self.destinationViewController;
toVC.view.alpha = 0;
[fromVC addChildViewController:toVC];
[fromVC.view addSubview:toVC.view];
[UIView animateWithDuration:1.0 animations:^{
toVC.view.alpha = 1;
//fromVC.view.alpha = 0;
} completion:^(BOOL finished){
[toVC didMoveToParentViewController:fromVC];
}];
}
else
{
//Dismiss
}
}
And here is my FirstVC.m:
- (void)prepareForSegue:(MyCustomSegue *)segue sender:(id)sender
{
segue.isPresenting = YES;
}
- (UIViewController *)viewControllerForUnwindSegueAction:(SEL)action fromViewController:(UIViewController *)fromViewController withSender:(id)sender
{
return self;
}
- (UIStoryboardSegue *)segueForUnwindingToViewController:(UIViewController *)toViewController fromViewController:(UIViewController *)fromViewController identifier:(NSString *)identifier
{
return [[MyCustomSegue alloc] initWithIdentifier:identifier source:fromViewController destination:toViewController];
}
- (IBAction)unwindToFirstVC:(UIStoryboardSegue *)segue
{
NSLog(@"I am here");
}
All the necessary connections are done in the storyboard as well.
My problem is that -segueForUnwindingToViewController:
is never called.
As soon as -viewControllerForUnwindSegueAction:fromViewController:withSender:
is returned, my program crashes with the following exception:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not find a view controller to execute unwinding for <FirstViewController: 0x8e8d560>'
As of my understanding, the reason for the crash, is that I want my container view controller to be the one to handle the unwind segue action, which is not possible (because container view controller asks only its children to handle the unwind segue.
Is it correct? What can I do to solve my problem?
Thanks!