UINavigationControllerWithCompletionBlock 0.0.8

UINavigationControllerWithCompletionBlock 0.0.8

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Aug 2015

Maintained by Jérôme Morissard.



My other works

http://leverdeterre.github.io

UINavigationControllerWithCompletionBlock

The UINavigationController missing API ! (push / pop with optional completionBlock). The implementation use the navigationController delegate on UINavigationController itself.

This project provides :

  • A completionBlock to manage your push/pop events,
  • A safe way to push/pop multiple controllers at the same times.
   [self.navigationController popViewControllerAnimated:YES withCompletionBlock:NULL];
   [self.navigationController popViewControllerAnimated:YES withCompletionBlock:NULL];
   [self.navigationController popViewControllerAnimated:YES withCompletionBlock:NULL];
  • No more "Nested pop animation can result in corrupted navigation bar",
  • No more "Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted."
  • No more crash because of deallocated controllers between your multiple animations.

Image

New methods

- (void)pushViewController:(UIViewController *)viewController 
                 animated:(BOOL)animated 
      withCompletionBlock:(JMONavCompletionBlock)completionBlock;

- (void)popViewControllerAnimated:(BOOL)animated 
              withCompletionBlock:(JMONavCompletionBlock)completionBlock;
- (void)popToRootViewControllerAnimated:(BOOL)animated
                    withCompletionBlock:(JMONavCompletionBlock)completionBlock;

Swizzled methods

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated; 
- (UIViewController *)popViewControllerAnimated:(BOOL)animated;

Usage UINavigationController+CompletionBlock

  • (OPTIONAL) Activate Swizzling to redirect push/pop native calls to custom implementation. This swizzling is interesting if you don't want to replace all your push/pop methods, or, if you implement your own NavigationControllerDelegate.
typedef NS_OPTIONS(NSUInteger, UINavigationControllerSwizzlingOption) {
    UINavigationControllerSwizzlingOptionDelegate       = 1 << 0,
    UINavigationControllerSwizzlingOptionOriginalPush   = 1 << 1,
    UINavigationControllerSwizzlingOptionOriginalPop    = 1 << 2
};

+ (void)activateSwizzling;
+ (void)activateSwizzlingWithOptions:(UINavigationControllerSwizzlingOption)options;
  • Use the new pop/push methods (no need swizzling because your are calling custom methods)
[self.navigationController popViewControllerAnimated:YES withCompletionBlock:NULL];
[self.navigationController pushViewController:vc animated:YES withCompletionBlock:^(BOOL successful) {
   NSLog(@"Hi ! Push done !");
}];
  • Use "old" Apple API. (Required Swizzling). The native calls will be redirected to the new custom API with default NULL completionBlock.
[self.navigationController popViewControllerAnimated:YES];
[self.navigationController pushViewController:vc animated:YES];

Installation using pods

Just add the following line in your podfile

pod 'UINavigationControllerWithCompletionBlock'

Image