【问题标题】:Swift - TabBarController -> ViewController -> NavigationControllerSwift - TabBarController -> ViewController -> NavigationController
【发布时间】:2017-10-22 16:11:08
【问题描述】:

我有以下情况:

我有一个带有一些标签(ViewControllers)的 TabBarController。

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

这是我所做的:

  1. 我创建了一个新的 ViewController(DetailViewController)
  2. 我在 NavigationController 中嵌入了这个新的 ViewController(DetailViewController)
  3. 我创建了一个从“嵌入在 tabbarcontroller 中的 viewcontroller”到“new navigationcontroller”的 segue(Show)
  4. 我编码:

    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 丢失...

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

谢谢和问候!!

【问题讨论】:

  • 您是否尝试过以下设置:Tab Bar Controller -> Navigation Controller -> "viewcontroller which is embedded in the tabbarcontroller" -> Detail View Controller?这就是您通常使用UINavigationController...的方式...

标签: ios swift uinavigationcontroller uitabbarcontroller segue


【解决方案1】:

根据您的问题,我相信这就是您所需要的:

【讨论】:

    【解决方案2】:

    你做错了。 您不应该将 UIViewController 直接嵌入到 tabBarController 以获得所需的结果。

    来自 Storybaord,

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

    self.tabBarController?.hidesBottomBarWhenPushed = true
    

    【讨论】:

    • 嘿,谢谢你的回答,我更正了我的架构:Tabbar -> ViewController(embedded in NavigationBar) -> ViewController...,但没有我得到错误,接收器“TabBarController”没有标识符“shownavicontroller”,为什么?
    • 从 Storyboard 中选择从 DetailViewController 到 NextViewController 的 Segue。在右侧面板中选择后,您将看到 segue 的属性刚刚将标识符发送到“shownavicontroller”。对于视觉外观信息检查@Kegham 答案
    猜你喜欢
    • 1970-01-01
    • 2016-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多