Swift - TabBarController -> ViewController -> NavigationController

喜欢而已 提交于 2019-12-23 04:37:28

问题


i have the following situation:

I got a TabBarController with some tabs(ViewControllers).

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

Here is what i did:

  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
    }
    

What goes wrong:

  1. NavigationController is sliding from bottom to top... it should slide from left to right
  2. BackButton in NavigationController is missing
  3. TabBar in NavigationController is missing...

Anybody could help me with this issue?

Thanks and Greetings!!


回答1:


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

From Storybaord,

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



回答2:


According to your question i believe this is what you need:



来源:https://stackoverflow.com/questions/44122404/swift-tabbarcontroller-viewcontroller-navigationcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!