How to add additional button besides Back button normally required in details view of Table or UI View Controller of your iOS App for your Apple IDE Xcode Project

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

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

 

self.navigationItem.leftItemsSupplementBackButton = YES;

 
And supplement above code with 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

Leave a Reply

Your email address will not be published. Required fields are marked *