简体   繁体   中英

How to set title of navigation bar in storyboard?

I can't solve this despite my best efforts. I also consulted the Apple documentation and several related questions here and still I have a mental block on this.

Using Xcode 6, I embedded a table view controller in a navigation controller and could set the title of the navigation bar in the table view controller, but not in the two view controllers that are connected to the table view via segues.

I did think there was a navigation bar on these two view controllers because after I embedded the table view controller in the navigation controller, it blocked out my topmost textfield in both. I repositioned that so that isn't a problem, but in storyboard I still don't seem to be able to click inside the navigation bar to add a title and now having added a navigation bar manually to test it out, I can see that there is only one navigation bar in document outline.

So do you simply have to set the title of the navigation bar programmatically or with an IBOutlet or some such? Doesn't seem like you can click into it in story board.

I am pretty sure this is a bug in xCode... I have experienced the same issue and most of the time it was solved by restarting xCode.

** In addition you may be able to get it solved by doing:

Drag a Navigation item from the objects pane into the viewcontroller or tableviewcontroller. This seemed to work for me. I did notice that the navigation area was missing from the "Document Outline Pane".

I hope this helps.

I had the same problem while following apple's swift guid. Dubble-clicking the "navigation bar" did nothing for me. How I solved it:

1: Select the "navigation item" from the document outline pane.

2: Open the attributes-inspector.

3: Select the title field and write the title here instead.

尝试以编程方式设置标题 - > self.navigationItem.title = @“REGISTER”;

I had the same problem. What worked for me was to select the controller that I couldn't set the title on, click editor -> embed in -> Navigation controller.

Then you should be able to edit the title and when finished, delete the navigation controller and reconnect the two original controllers.

The screen that was previously embedded should now contain the title you created earlier.

这是你准备segue:[segue.destinationViewController setTitle:@“New Task”];

在嵌入控制器时,一定要使用关系Segue,而不是手动Segue。

Update to this issue if someone else need it:

  1. Make a segue between ViewControllers
  2. Pick Kind option as Show(e. Push)
  3. Than change this Kind option on some deprecated - ex. Push
  4. Now you can edit your tittle and navigation items from storyboard
  5. Remember to change Kind option again on what you need.

None of the answers worked for me.

This worked:

  1. Delete nav connection
  2. Ctrl drag a new nav connection
  3. Make it a show connection
  4. Now you can edit the title
  5. Delete the nav connection again
  6. Create the original nav connection type again

It seems that this is indeed a bug in IB 🙁

You can also set the view controller's "title" property instead, which will automatically set the title of a navigation item or tab bar item.

By selecting the view controller in the storyboard, you can set the title under "View Controller" in the Attributes inspector (Xcode 9):

在此输入图像描述

将您的导航项连接到您的类(即UIViewController),并通过在viewDidLoad中编写以下内容以编程方式访问它的标题:

navigationItem.title = "whateverTextHere"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM