Custom UIStoryboardSegue using segueWithIdentifier:source:destination:performHandler:
The point of segueWithIdentifier:source:destination:performHandler:
- Provide an alternative to
UIViewController performSegueWithIdentifier:sender
in cases where you also want to create a custom transition, without creating a segue subclass. - Vend a segue that can be used as the return for
segueForUnwindingToViewController:fromViewController:identifier
As noted above, this approach is only viable for segues which you would call manually -- i.e. not for segues that would otherwise be triggered via IB triggers.
So, for example, if you have a segue that needs to be triggered after a certain timeout period (such as a custom lock-screen), you could use segueWithIdentifier:source:destination:performHandler:
to handle the custom transition.
-(void)appTimeoutLockScreen{ UIStoryboardSegue *segue = [UIStoryboardSegue segueWithIdentifier:@"LockScreenSegue" source:sourceVC destination:destinationVC performHandler:^{ // transition code that would // normally go in the perform method }]; // Dev is responsible for calling prepareForSegue and perform. // Note, the order of calls for an IB triggered segue as well as // a performSegueWithIdentifier segue is perform first, then // prepareForSegue:sender. Manual segues need to inverse the call // in order to ensure VC setup is finished before transition. [self prepareForSegue:segue sender:self]; [segue perform];}
Another practical use for the method is unwinding segues. Using a similar scenarioto the previous example, we could use it to return a segue to transition from a lock screen back to the previous viewController:
-(UIStoryboardSegue *)segueForUnwindingToViewController:(UIViewController*)toVC fromViewController:(UIViewController *)fmVC identifier:(NSString *)identifier{ UIStoryboardSegue *segue = [UIStoryboardSegue segueWithIdentifier:@"FromLockScreenSegue" source:fmVC destination:toVC performHandler:^{ // transition code }]; return segue;}