简体   繁体   中英

How to segue to view controller from TabbarController?

I have a TabbarController with is the entry point of my app.So I want to segue for this TabbarController to ViewControllerA . I perform performSegue(with: "identifier") .I can reach the ViewControllerA ,but when I reach ViewControllerA there is no NavigationBar

I tried to embed ViewControllerA into a NavigationController 1st,so the storyboard look like this

TabbarController-> NavigationController -> ViewControllerA

By this,I can reach ViewControllerA.But I have problem in prepareForSegue method.Cause I need to include a value in the segue,now the value seem not included.

My code in prepareForSegue is look like this :

if let VcA = segue.destination.navigationController?.topViewController as? ViewControllerA {
  VcA.postId = sender as! Int
}else{
   print("cant work")
}

And I also tried to embed the tabbarController to a NavigationController,but in Xcode-> Editor -> Embed the option is being disable.

So my question is

how to segue from a TabbarController to ViewController and in destination the NavigationBar is visible and can go back to previous screen?

Assuming that your storyboards looks similar to:

在此处输入图片说明

That's because you are calling performSegue(with: "identifier") in the TabbarController which does not directly connected to the segue. What you should do instead so to implement it in the first view controller which connected to the navigation controller ( ViewControllerA ). So, it would be -for instance- something like this:

class ViewControllerA: UIViewController {
    // ...

    override func viewDidLoad() {
        super.viewDidLoad()

        performSegue(with: "identifier")

    }

    // ...
}

Thus your segue should be from ViewControllerA to the desired view controller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM