Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to push a View Controller with a completion block?

UINavigationController's documentation contains no pushViewController methods with a completion: parameter.

like image 517
user3300062 Avatar asked Feb 13 '14 02:02

user3300062


People also ask

What is a navigation controller Swift?

A navigation controller is a container view controller that manages one or more child view controllers in a navigation interface. In this type of interface, only one child view controller is visible at a time.


2 Answers

The better solution would be wrapping the push animation by an CATransaction and set the completionBlock. There's no need to deal with timings.

[CATransaction begin];
[CATransaction setCompletionBlock:^{
    //whatever you want to do after the push
}];
[[self navigationController] pushViewController:viewController animated:YES];
[CATransaction commit];
like image 159
justMartin Avatar answered Oct 11 '22 15:10

justMartin


justMartin's answer worked great for me. For those new to using swift API:

CATransaction.begin()
navigationController?.pushViewController(viewController, animated: true)
CATransaction.setCompletionBlock({ 
    //your post animation logic
})
CATransaction.commit()
like image 26
Ishaan Sejwal Avatar answered Oct 11 '22 17:10

Ishaan Sejwal