Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do a "show (e.g Push)" segue programatically without animation?

How can I do a "show (e.g Push)" segue programatically without animation? None of the solutions I've found works the same way as the one in storyboard.

like image 789
Morten Stulen Avatar asked Jun 22 '15 19:06

Morten Stulen


1 Answers

What the show (e.g. Push) segue does internally is to call
-[UIViewController showViewController:sender:]

Calling this method on your view controller itself, will trigger the appropriate way of presenting the view controller you are passing.

// Swift
self.showViewController(viewControllerToShow, sender: self)
// Objective-C
[self showViewController: viewControllerToShow sender: self];

The animation can be removed, by wrapping the call in an +[UIView performWithoutAnimation:] block.

// Swift
UIView.performWithoutAnimation {
    self.showViewController(viewControllerToShow, sender: self)
}
// Objective-C
[UIView performWithoutAnimation:^void () {
    [self showViewController: viewControllerToShow sender: self];
}]
like image 182
Tim Bodeit Avatar answered Nov 14 '22 22:11

Tim Bodeit