Storyboard UINavigation Controller Back Button Text

梦想的初衷 提交于 2019-12-19 04:02:12

问题


In XCode 4.5.1 creating a storyboard app with a Navigation controller, I am having a hard time trying to set the BACK button for any view controllers that are pushed. I'm using segue's and the view controller shows as expected. However I want to change the name of the navigation bar and back button dynamically and placed this in my ViewWillAppear:

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

changes the title of the navigation bar but the back button still displays the NAME of the pushed window rather than the text "Add".

The Simulated Metrics are all Inferred. I also added a BarButtonItem to the black tray below the view in Xcode and wired up the backButton of the viewcontroller to the backButton, yet the text still does not appear.

Adding the following log messages also yield something interesting: (and yet the titlebar is updating 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)

回答1:


The back button will show the title of the previous view and if no title is set it'll show 'Back'.

So in your prepareForSegue method, you can change the title of the current view before the next view is pushed. The back button will then show whatever you set the title to.




回答2:


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

  1. Open StoryBoard
  2. In Document Outline window find ViewController to which you want to return to
  3. Click on Navigation Item of that ViewController
  4. In Attributes explorer change Back Button value to your custom tile

That is it, enjoy...



来源:https://stackoverflow.com/questions/12886274/storyboard-uinavigation-controller-back-button-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!