2
votes

I need to intercept when iOS substitute the standard previous viewcontroller title with the standard "back" title.

From Apple Developer site https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationItem_Class/#//apple_ref/occ/instp/UINavigationItem/backBarButtonItem

Note

If the title of your back button is too long to fit in the available space on the navigation bar, the navigation bar may substitute the string “Back” in place of the button’s original title. The navigation bar does this only if the back button is provided by the previous view controller. If the new top-level view controller has a custom left bar button item—an object in the leftBarButtonItems or leftBarButtonItem property of its navigation item—the navigation bar does not change the button title.

So, I need to intercept when it will done, to change the back text with my custom title otherwise leave the previous ViewController title.

(I change the back title in viewDidLoad() with this command and work very well:

navigationController?.navigationBar.topItem?.backBarButtonItem = UIBarButtonItem(title: "my title", style: .Plain, target: nil, action: nil)
1

1 Answers

-1
votes

You could easily just check what length of string makes it too long, and if your custom title is that length, change the title of the back button. However, that wouldn't be good for different screen sizes.

I think a better solution is to just push from a previous view controller. Is there any reason you can't push from a previous controller? I assume that if you want the "back" function, then you're already pushing from somewhere, so it shouldn't be an issue.