简体   繁体   English

导航栏项目不可见

[英]Navigation bar items are invisible

Xcode 10, Swift 5 Xcode 10,Swift 5

I'm trying to create a button on the navigation bar but I can't get it to actually be displayed. 我正在尝试在导航栏上创建一个按钮,但无法使其真正显示出来。 The setup of my project is: 我的项目的设置是:

  1. ViewController1 (VC1, yellow): "Click" button that starts segue to ViewController1(VC1,黄色):“点击”按钮,开始搜索到
  2. NavigationController (NC): Segue to NavigationController(NC):搜索到
  3. ViewController2 (VC2, red): "Next" button that loads ViewController2(VC2,红色):加载的“下一步”按钮
  4. ViewController3 (VC3, green) ViewController3(VC3,绿色)

Embedding VC2 in a UINavigationController and connecting it to VC3 with a segue automatically creates a "Back" button in VC3. 将VC2嵌入UINavigationController并通过segue将其连接到VC3会在VC3中自动创建一个“后退”按钮。

在此处输入图片说明

How do I make my "Button" on the right in the UINavigationBar in VC3 become visible - using only the Storyboard? 如何仅使用Storyboard使VC3中UINavigationBar右侧的“按钮”可见?

The mistake I made was to add a UINavigationBar , which was added behind the existing UINavigationBar and because of this all of its items were invisible! 我犯的错误是添加了一个UINavigationBar ,它被添加到现有的UINavigationBar后面,因此它的所有项目都是不可见的!

A UINavigationBar that was automatically added by a UINavigationController doesn't show up in the hierarchy! UINavigationBar自动添加的UINavigationController不会显示在层次结构中! There'll be one if there's a "back" button, so in this case add a UINavigationItem instead. 如果有一个“后退”按钮,将只有一个,因此在这种情况下,请添加UINavigationItem This creates a Title item. 这将创建一个Title项目。

Drag the new item you want to add over the left or right side of the UINavigationBar and there'll be a blue square, indicating where you can drop it. 将要添加的新项目UINavigationBar的左侧或右侧,将出现一个蓝色方框,指示您可以将其放在哪里。 This item can be a UIBarButtonItem (which can be linked up like a button), a UIButton (which automatically also creates a UIBarButtonItem ),... or even a UIView . 此项可以是UIBarButtonItem (可以像按钮一样链接起来), UIButton (也可以自动创建UIBarButtonItem ),...甚至UIView Dropping an item adds it to the hierarchy and if it's the very first one, two new children are also going to be added to the Title : 删除项目会将其添加到层次结构中,如果这是第一个项目,则还将在Title添加两个新的子级:

  1. Left Bar Button Items 左栏按钮项目
  2. Right Bar Button Items 右栏按钮项目

在此处输入图片说明

Important: Adding something to the left "drop zone" overwrites the "back" button, which means that you're going to have to deal with going back to the previous screen yourself. 重要说明:在左侧的“放置区域”中添加一些内容会覆盖“后退”按钮,这意味着您将不得不自己返回到上一屏幕。 This is easily accomplished by creating an "onClick" action for this item (ctrl+drag to the .swift file) and then calling: 通过为此项目创建一个“ onClick”操作(按ctrl键并拖动到.swift文件),然后调用以下命令,可以轻松实现此目的:

navigationController?.popViewController(animated: true)

在此处输入图片说明

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

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