Changing the name of the back button when you click the UIViewController on a UITableViewController

View hierarchy:

UINavigationController ->UITableViewController(1) ->UITableViewController(2) ->UIViewController(3) 

In 1 and 2, I have this code:

 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { self.navigationItem.backBarButtonItem?.title = "" } 

It should override the title of the back button on the next view controller, pressed on the current controller. It works from 1 → 2. But it does not work for 2 → 3. In 3, the name of the back button has a title, the name of the previous UITableViewController.

Any ideas on something wrong? I use swift, xcode6.1 and iOS8.1

+6
source share
2 answers

You can create a new return button without a title. Just put this in the viewDidLoad () of each view controller.

 self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: UIBarButtonItemStyle.Plain, target: nil, action: nil) 

-

I am going to extend this answer with my experience. Therefore, I was able to remove the title of the back button to display only the back arrow. In the storyboard, you must select a navigation element that displays a title inside the navigation bar of the previous view controller. There is a property called Back Button . Just enter a space and save. It will remove the button title.

The UIBarButtonItemStyle.Bordered update has UIBarButtonItemStyle.Bordered deprecated in iOS 8.0. Use UIBarButtonItemStyle.Plain .

+10
source

thank you, if you want to use the image of the customer return button, you can use this

  self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "backImage") self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: " backImage") self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: UIBarButtonItemStyle.Plain, target: nil, action: nil) 
0
source

Source: https://habr.com/ru/post/977872/


All Articles