Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

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
You can’t perform that action at this time.