Search code examples
iosuiviewcontrolleruinavigationbaruibarbuttonitemuinavigationitem

Unable to set back button on UINavigationController


I'm presenting my view controller with the following code:

UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:sessionController];
[self presentViewController:navigation animated:YES completion:^{
}];

In the "viewDidLoad" method of my presented view controller I'm attempting to set the "back button" as follows:

UIBarButtonItem *newBackButton =
[[UIBarButtonItem alloc] initWithTitle:@"Test"
                                 style:UIBarButtonItemStyleBordered
                                target:nil
                                action:nil];
[self.navigationController.navigationItem setBackBarButtonItem:newBackButton];

Silent failure, no exception, no log, no error, and NO button. Any thoughts would be much appreciated!


Solution

  • You can try:

    self.navigationItem.leftBarButtonItem = newBackButton