UINavigation Controller Back Button Text Storyboard

In Xcode 4.5.1, creating a storyboard application with a navigation controller, I find it difficult to set the BACK button for any view controllers that have been pressed. I am using segue and the view controller shows as expected. However, I want to dynamically change the name of the navigation bar and back button and put this in my ViewWillAppear:

self.title = @"Select Songs"; [self.backButton setTitle:@"Add"]; 

changes the name of the navigation bar, but the back button still displays the name NAME in the pressed window, rather than the text Add.

Simulated metrics are all inferred. I also added a BarButtonItem to the black tray under the view in Xcode and connected the backButton to the viewcontroller to the backButton, but the text is still not displayed.

Adding the following log messages also gives something interesting: (and yet the header is updated correctly)

 -(void) viewDidAppear:(BOOL)animated { NSLog(@"%s %@", __FUNCTION__, self.navigationItem.backBarButtonItem); NSLog(@"%s %@", __FUNCTION__, self.navigationController.navigationItem.backBarButtonItem); } 2012-10-14 15:18:41.835 xxxx[2690:907] -[ViewController viewDidAppear:] (null) 2012-10-14 15:18:41.838 xxxx[2690:907] -[ViewController viewDidAppear:] (null) 
+4
source share
2 answers

The back button will display the title of the previous view, and if no name is given, it will display back.

So, in your prepareForSegue method, you can change the title of the current view before clicking on the next view. Then the back button will show everything you set the title to.

+8
source

The accepted answer is hacking, this is the way to do it ...

  • Open storyboard
  • In the Document Structure window, find the ViewController for which you want to return to
  • Click the navigation item of this ViewController
  • In changing the attribute explorer, the value of the Back button for your custom tile

That is, enjoy ...

+12
source

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


All Articles