简体   繁体   English

如何在故事板中设置导航栏的标题?

[英]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. 我也在这里咨询了Apple文档和几个相关的问题,但我仍然有一个心理障碍。

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. 使用Xcode 6,我在导航控制器中嵌入了一个表视图控制器,可以在表视图控制器中设置导航栏的标题,但不能在通过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? 那么你只需要以编程方式设置导航栏的标题,还是使用IBOutlet或其他类似设置? 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. 我很确定这是xCode中的一个错误...我遇到了同样的问题,大部分时间都是通过重启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. 将导航项从对象窗格拖到viewcontroller或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. Dubble-点击“导航栏”对我没有任何帮助。 How I solved it: 我是如何解决的:

1: Select the "navigation item" from the document outline pane. 1:从文档大纲窗格中选择“导航项”。

2: Open the attributes-inspector. 2:打开属性检查器。

3: Select the title field and write the title here instead. 3:选择标题字段并在此处写下标题。

尝试以编程方式设置标题 - > 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 在ViewControllers之间制作一个segue
  2. Pick Kind option as Show(e. Push) 选择种类选项作为显示(e。推送)
  3. Than change this Kind option on some deprecated - ex. 比在某些已弃用的更改此Kind选项 - 例如。 Push
  4. Now you can edit your tittle and navigation items from storyboard 现在,您可以从故事板编辑您的tittle和导航项目
  5. Remember to change Kind option again on what you need. 请记住再次根据需要更改Kind选项。

None of the answers worked for me. 这些答案都不适合我。

This worked: 这有效:

  1. Delete nav connection 删除导航连接
  2. Ctrl drag a new nav connection Ctrl拖动新的导航连接
  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 🙁 看来这确实是IB bug中的一个错误

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): 通过在故事板中选择视图控制器,可以在“属性”检查器(Xcode 9)中的“视图控制器”下设置标题:

在此输入图像描述

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

navigationItem.title = "whateverTextHere"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Main.storyboard中具有参考的其他Storyboard中为导航控制器设置选项卡图标和标题? - How to set tab bar icon and title for a Navigation controller in different Storyboard which has reference in Main.storyboard? 设置导航栏标题 - Set title of navigation bar 如何设置导航栏标题的字体大小 - How to set the font size of navigation bar title 如何设置右导航栏按钮标题 - How to set right navigation bar button title 如何以编程方式设置导航栏的标题? - How to set the title of a Navigation Bar programmatically? 情节提要中导航栏标题视图中的UIButton和标签 - UIButton and Labels in Navigation Bar Title View in Storyboard 如何为UIPopOverController的导航栏设置标题? - How to set title to UIPopOverController's Navigation Bar? 导航栏标题未显示在情节提要屏幕上 - Navigation Bar Title Not Displaying On Storyboard Screen 更改拖动到情节提要中的导航栏的标题 - Change title of a Navigation Bar dragged in storyboard 我不能同时在情节提要中将标题和图像同时设置到导航栏上的右侧栏项目吗? - Cann't I set title and Image to the right bar item on navigation bar at the same time in storyboard?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM