Skip to content

Instantly share code, notes, and snippets.

@nebiros
Last active January 1, 2016 05:19
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 nebiros/8097686 to your computer and use it in GitHub Desktop.
Save nebiros/8097686 to your computer and use it in GitHub Desktop.
Custom back button as navigation item left bar button.
#import "MyViewController.h"
#import "UIViewController+JIMBackButton.h"
@interface MyViewController ()
@end
@implementation MyViewController
#pragma mark - UIViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self jim_setupCustomBackButton];
}
//
// UIViewController+JIMBackButton.h
// CupMaster
//
// Created by Juan Felipe Alvarez Saldarriaga on 11/7/13.
// Copyright (c) 2013 CupMaster. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIViewController (JIMBackButton)
- (void)jim_setupCustomBackButton;
@end
//
// UIViewController+JIMBackButton.m
// CupMaster
//
// Created by Juan Felipe Alvarez Saldarriaga on 11/7/13.
// Copyright (c) 2013 CupMaster. All rights reserved.
//
#import "UIViewController+JIMBackButton.h"
@implementation UIViewController (JIMBackButton)
- (void)jim_setupCustomBackButton
{
self.navigationItem.hidesBackButton = YES;
if ([self.navigationController.viewControllers count] <= 0) {
return;
}
if ([self.navigationController.visibleViewController isEqual:self.navigationController.viewControllers[0]]) {
return;
}
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"⬅︎" style:UIBarButtonItemStylePlain target:self action:@selector(jim_customBackButtonPressed:)];
}
- (IBAction)jim_customBackButtonPressed:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
@end
@seivan
Copy link

seivan commented Dec 23, 2013

Don't return in middle of statements unless it has an advantage of readability, e.g. a big-ass if statement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment