A user arrives at this viewController from the previous one through a push segue, so I want there to be a back button in the UINavigationBar
to allow them to return.
Normally this back button would appear by default if I right clicked on the viewController in storyboard and selected Embed in
> Navigation Controller
, but doing this is causing crashes, and I prefer doing things programmatically, so I decided to do it in viewDidLoad
like so:
// Nav bar
UINavigationBar *navbar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
// Back Button
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:self action:@selector(Back)];
self.navigationItem.leftBarButtonItem = backButton;
[self.view addSubview:navbar];
This successfuly adds a navigation bar up top, but it doesn't add the back button as expected. I've tried the solutions given here, here, and here, but none have solved the problem.