添加NavigationController不会显示后退按钮

问题描述 投票:0回答:1

我正在尝试将“后退”按钮添加到我的几个视图中,以查看它们之前的特定视图。

视图A有2个按钮,用于查看B和C,我想要B和C(以及所有后面的视图)都有“后退按钮”,但我不希望它出现在我在视图A中。

在这个例子中,我只展示我对视图A和B所做的事情。

Views A and B

我在A和B之间添加了导航控制器,如您所见,勾选了“显示导航栏”。 A和B之间的segue“以模态存在”。由于某种原因,它没有显示在我的故事板中,但视图A是连接到tabbarController的选项卡式视图。我究竟做错了什么 ?

xcode uinavigationcontroller uitabbarcontroller
1个回答
1
投票

你的根视图控制器(基本上是第一个)需要是一个UINavigationController才能让导航栏和后退按钮本地工作。

此外,以模态方式呈现UIViewController不会显示导航栏(以及随后的后退按钮)。只有当您将UIViewController推入导航堆栈时,才会显示导航栏和后退按钮。

以下是从UINavigationController中的另一个视图控制器推送视图控制器的示例:

 func buttonPressed() {
     let nextViewController = UIViewController()
     self.navigationController?.pushViewController(nextViewController, animated: true)

     // As long as your navigation bar is not set to hidden, 
     // doing this will push nextViewController onto the navigation stack 
     // and show the back button + navigation bar.
 }
© www.soinside.com 2019 - 2024. All rights reserved.