Coder Social home page Coder Social logo

leverdeterre / uinavigationcontrollerwithcompletionblock Goto Github PK

View Code? Open in Web Editor NEW
138.0 11.0 13.0 2.25 MB

The UINavigationControllerWithCompletionBlock missing API !

License: MIT License

Ruby 0.46% Objective-C 94.85% Swift 0.67% C 0.65% C++ 0.17% Shell 3.21%

uinavigationcontrollerwithcompletionblock's Introduction

My other works

[http://leverdeterre.github.io] (http://leverdeterre.github.io)

UINavigationControllerWithCompletionBlock

Twitter License MIT CocoaPods Travis

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.