In my app I have UINavigationController with two UIViewControler's (first and second). The first view controller contain UITableView. When a cell of table is touched the second view controller is pushed. What I want is to set custom text to back button at the second view. Here is the code in second view.
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.leftBarButtonItem =
[[[UIBarButtonItem alloc] initWithTitle:@"Go back"
style:UIBarButtonItemStyleBordered
target:nil
action:nil] autorelease];
}
The problem is that the text of back button is changed but second view controller is not removed from the stack when the button is touched.
This has been already asked so many times:
The back button ( self.navigationItem.backBarButtonItem
) must be set instead of left button and not in the second controller, but in the first one (root).
The 'back' button applies to the controller doing the pushing. In this case, you would want to assign the custom back button in your 'first' UIViewController. When you push the second view controller, the back button will show the proper text
You are trying to set the propert of the leftbarbuttonitem.
To avail the default properties of back bar button, just use
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
This would pop out the pushed view from the navigation controller and also enable you to go back to the last view.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.