How can I create a back button of a navigation controller programmatically?
Asked
Active
Viewed 1.6k times
7
-
3http://stackoverflow.com/questions/1441699/uinavigationcontroller-back-button-custom-text – jbat100 Nov 18 '11 at 09:00
-
This method has been deprecated in iOS 8 :/ – Arjun Sahni Jul 06 '15 at 18:16
1 Answers
25
In -(void)loadView
or similar:
UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStyleBordered target:self action:@selector(backPressed:)];
self.navigationItem.leftBarButtonItem = btn;
[btn release];
-(void)backPressed: (id)sender
{
[self.navigationController popViewControllerAnimated: YES]; // or popToRoot... if required.
}

Luke
- 11,426
- 43
- 60
- 69
-
Thanks for the feedback. It was my mistake, I had self.navigationItem.hidesBackButton=YES; in 1 method of my code, I didn't realize it and so finally wrote in a question. Agreed,I should I have done some more research on my code .. – user1048396 Nov 18 '11 at 10:00