[英]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: 我的项目的设置是:
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
添加两个新的子级:
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.