iOS: Displaying "Back" on the back button instead of the title of the previous UIViewController

The back button typically shows the title of the previous UIViewController, unless it's empty. However, sometimes you don't want to show the title of the previous. Sometimes you have a title that just doesn't make sense to show on the back button.

The easy option is to simply set the back button title yourself to @"Back" with the caveat that it will always be English, no matter what the device's configured language is. The better solution is to temporarily remove the title in the previous UIViewController and re-set it when returning.
 [super viewWillAppear:animated];
 self.title = @"My title";
 self.title = nil;
 [super viewWillDisappear:animated];
This way iOS will automatically set the title to "Back" or to the equivalent for whatever language is configured for the device.

I've just launched a new side project of mine:

Bugfender - A modern remote logger tailor-made for mobile development

It's currently free and you can sign up here:

Any kind of feedback is more than appreciated :-)

No comments:

Post a Comment