How to set the text of a back button on a UINavigationBar? [duplicate]

The setTitle way – though may seem to work, is incorrect. If you pay attention closely, you will notice that the navigation item changes to the new title while the new view is animated into view via pushViewController. The fact that you have to restore your title in viewWillAppear is kludgy, which further suggests its hack nature.

The correct way is to do the following before your pushViewController:

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] 
                                initWithTitle: @"Back Button Text" 
                                style: UIBarButtonItemStyleBordered
                                target: nil action: nil];

[self.navigationItem setBackBarButtonItem: backButton];
[backButton release];

Leave a Comment