Reputation: 7639
I use a UINavigationController in my app and am having an issue with the back button titles. I have the title programmatically set for any page that I push to. On some of the pages the back button will correctly display the previous pages title, but then on select other pages it just says 'back'.
I have a basic implementation on pushing to a new VC:
- (void)pushToNewVC
{
NewVC *newVC = [[NewVC alloc] init];
[self.navigationController pushViewController:newVC animated:YES];
}
In the viewDidLoad
of newVC/all of myVC's I have self.title = @"Title"
.
The problem is that in some cases it works, but then in others in will just say 'Back' rather than the previous pages title.
Upvotes: 1
Views: 724
Reputation: 3854
I've noticed a similar behavior that if the back button's title length won't fit in the Navigation Bar with the title of the pushed VC, the Back Button's title will fallback to just < Back
.
On the VCs where the inconsistent behavior is happening, try setting the title of pushing VC to a shorter word just to test and confirm if that is indeed what's happening. Hope this helps.
Upvotes: 2
Reputation: 1044
Setting self.title = @"Title" will just set the title og the UINavigationBar, not the back button. Use the following code to set the back button title:
UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
initWithTitle: @"Back Button Text"
style: UIBarButtonItemStyleBordered
target: nil action: nil];
[self.navigationItem setBackBarButtonItem: backButton];
Upvotes: 0