Swift - TabBarController ->视图控制器 ->导航控制器 [英] Swift - TabBarController -> ViewController -> NavigationController

查看:54
本文介绍了Swift - TabBarController ->视图控制器 ->导航控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下情况:

我有一个带有一些选项卡(ViewControllers)的 TabBarController.

I got a TabBarController with some tabs(ViewControllers).

当我在这些 ViewControllers 中的一个中时,我点击一个按钮,我想转到 NavigationController 并且仍然看到标签栏...

When i am in one of these ViewControllers, i tap a button and i want to segue to a NavigationController AND still see the tabbar...

这是我所做的:

  1. 我创建了一个新的 ViewController(DetailViewController)
  2. 我将这个新的 ViewController(DetailViewController) 嵌入到 NavigationController 中
  3. 我创建了一个从嵌入在 tabbarcontroller 中的视图控制器"到新导航控制器"的 segue(Show)
  4. 我编码:

  1. I created a new ViewController(DetailViewController)
  2. I embedded this new ViewController(DetailViewController) in a NavigationController
  3. I created a segue(Show) from the "viewcontroller which is embedded in the tabbarcontroller" to the "new navigationcontroller"
  4. I coded:

func buttonTapped {
    performSegue(withIdentifier: "shownavicontroller", sender: nil
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {        
    let destinationNavigationController = segue.destination as! UINavigationController
    let targetController = destinationNavigationController.topViewController as! DetailViewController
}

出了什么问题:

  1. NavigationController 从下往上滑动...它应该从左往右滑动
  2. NavigationController 中的 BackButton 缺失
  3. 缺少 NavigationController 中的 TabBar...

有人可以帮我解决这个问题吗?

Anybody could help me with this issue?

谢谢和问候!!

推荐答案

你做错了.您不应该将 UIViewController 直接嵌入到 tabBarController 以获得您想要的结果.

You have done wrong. You should not embed UIViewController directly to tabBarController to get the desired result you want.

来自 Storybaord,

如果你是从故事板设计你的应用程序,那么你应该添加一个 UIViewController 并将这个 UIViewController 对象嵌入到 UINavigationController 中,然后嵌入这个 <UITabBarController 中的 code>NavigationController.因此,如果按下上面 UIViewController 中的按钮,并且您需要打开另一个 UIViewController 不是从底部到顶部而是从左到右,并期望在顶部有一个自动后退按钮栏和隐藏底部栏.然后你需要在 ViewController 上创建一个 Push/Show Segue 表单(嵌入 NavigationController -> 嵌入 TabBarController)到你的新 UIViewController打开.在调用 push/show segue 之前,您需要编写以下几行.

If you are designing your application from storyboard then you should add a UIViewController and embed this UIViewController object into UINavigationController and then embed this NavigationController in a UITabBarController. So that if a button in above UIViewController is pressed and you need to open an other UIViewController not form Bottom to Top but from Left to Right and expecting a Automatic back button at top bar and hide bottom bar. Then you need to create a Push/Show Segue form Above ViewController (Embed in NavigationController -> Embed in TabBarController) to you new UIViewController that will open. And before calling the push/show segue you need to write bellow lines.

self.tabBarController?.hidesBottomBarWhenPushed = true

这篇关于Swift - TabBarController ->视图控制器 ->导航控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆