Swift - TabBarController -> ViewController -> Navi

2019-06-13 15:56发布

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

2条回答
爷、活的狠高调
2楼-- · 2019-06-13 16:30

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

enter image description here

enter image description here

查看更多
三岁会撩人
3楼-- · 2019-06-13 16:34

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
查看更多
登录 后发表回答