Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d4r1091/ef69ea6b1750796d6f20 to your computer and use it in GitHub Desktop.
Save d4r1091/ef69ea6b1750796d6f20 to your computer and use it in GitHub Desktop.
//
// UINavigationController+CompletionHandler.h
// Entire
//
// Created by ChristianEnevoldsen on 10/08/14.
// Copyright (c) 2014 Reversebox. All rights reserved.
//
// Forked by Dario Carlomagno on 03/10/14.
// Copyright (c) 2014 Monksoftware. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UINavigationController (CompletionHandler)
- (void)pushViewController:(UIViewController *)viewController
animated:(BOOL)animated
completion:(void (^)(void))completion;
- (void)popViewController:(UIViewController *)viewController
animated:(BOOL)animated
completion:(void (^)(void))completion;
- (void)popToRootViewControllerAnimated:(BOOL)animated
completion:(void (^)(void))completion;
@end
//
// UINavigationController+CompletionHandler.m
// Entire
//
// Created by ChristianEnevoldsen on 10/08/14.
// Copyright (c) 2014 Reversebox. All rights reserved.
//
// Forked by Dario Carlomagno on 03/10/14.
// Copyright (c) 2014 Monksoftware. All rights reserved.
//
#import "UINavigationController+CompletionHandler.h"
#import <QuartzCore/QuartzCore.h>
@implementation UINavigationController (CompletionHandler)
- (void)pushViewController:(UIViewController *)viewController
animated:(BOOL)animated
completion:(void (^)(void))completion
{
[CATransaction begin];
[CATransaction setCompletionBlock:completion];
[self pushViewController:viewController animated:animated];
[CATransaction commit];
}
- (void)popViewController:(UIViewController *)viewController
animated:(BOOL)animated
completion:(void (^)(void))completion
{
[CATransaction begin];
[CATransaction setCompletionBlock:completion];
[self popViewController:[self backViewController] animated:animated];
[CATransaction commit];
}
- (void)popToRootViewControllerAnimated:(BOOL)animated
completion:(void (^)(void))completion
[CATransaction begin];
[CATransaction setCompletionBlock:completion];
[self popToRootViewControllerAnimated:animated];
[CATransaction commit];
}
- (UIViewController *)backViewController
{
NSInteger numberOfViewControllers = self.viewControllers.count;
if (numberOfViewControllers < 2)
return nil;
else
return [self.navigationController.viewControllers objectAtIndex:numberOfViewControllers - 2];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment