Skip to content

Instantly share code, notes, and snippets.

@hspinks
Created October 9, 2014 01:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hspinks/d2167ff08341720662bf to your computer and use it in GitHub Desktop.
Save hspinks/d2167ff08341720662bf to your computer and use it in GitHub Desktop.
HSNavigationController
#import <UIKit/UIKit.h>
@interface HSNavigationController : UINavigationController
@end
#import "HSNavigationController.h"
@interface HSNavigationController() <UINavigationControllerDelegate>
@end
@implementation HSNavigationController
#pragma mark - NavigationController Delegate
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
/* Hide navigation bar if root controller */
if ([navigationController isEqual:self] && [viewController isEqual:[self.viewControllers firstObject]]) {
[self setNavigationBarHidden:YES animated:animated];
} else {
[self setNavigationBarHidden:NO animated:animated];
}
}
#pragma mark - Initialization
- (void)setup
{
self.delegate = self;
}
- (instancetype)init
{
self = [super init];
if (self) {
[self setup];
}
return self;
}
- (instancetype)initWithNavigationBarClass:(Class)navigationBarClass toolbarClass:(Class)toolbarClass
{
self = [super initWithNavigationBarClass:navigationBarClass toolbarClass:toolbarClass];
if (self) {
[self setup];
}
return self;
}
- (instancetype)initWithRootViewController:(UIViewController *)rootViewController
{
self = [super initWithRootViewController:rootViewController];
if (self) {
[self setup];
}
return self;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment