How do you add a button beside the back button, which is usually required in the details view of the table or UI View Controller of your iOS app for your Apple Xcode Project?

It always occurs when you are using the table view controller in your iOS Xcode project & when you navigate from the table view cell to the detail view of your app in the storyboard on the iOS Simulator or the actual device, the ‘Back,’ button Appears at the top left. What if you want to add a button beside the ‘Back’ button, And you want to know how? Here is the solution,

You have to add the following code in your ‘viewdidLoad’ function in your desired ViewController.m file:

self.navigationItem.leftItemsSupplementBackButton = YES;

And supplement above code with the following code to call button:

UIBarButtonItem *share = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(shareAction)];
    self.navigationItem.leftBarButtonItems = [self.navigationItem.leftBarButtonItems arrayByAddingObject:share];

Now your viewDidLoad function should look like this:

- (void)viewDidLoad
{
    NSLog(@"viewDidLoad");
    [super viewDidLoad];

    // Do any additional setup after loading the view.
    self.navigationItem.leftItemsSupplementBackButton = YES;

    UIBarButtonItem *share = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(shareAction)];
    self.navigationItem.leftBarButtonItems = [self.navigationItem.leftBarButtonItems arrayByAddingObject:share];
}

Hope it helps,

Thanks & Regards
Mandar Apte

Published by Mandar Apte

Mandar is a Mumbai-based multi-disciplinary designer with UX/UI, Logo, Symbol, and Brand Identity design expertise. He currently runs his Mudrkashar Linguistic Apple iPhone, iPad, and Mac app business in the heart of Mumbai city.

Leave a comment

Leave a Reply