1

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?

ken
  • 2,426
  • 5
  • 43
  • 98
  • When you embed ViewControllerA.And in NavigationController, what did you see after segue. – Nitish Mar 12 '18 at 10:30
  • "I perform `performSegue(with: "identifier")`" in which file? it should be in the `ViewControllerA`... – Ahmad F Mar 12 '18 at 10:31
  • in TabbarController bro @AhmadF – ken Mar 12 '18 at 10:33
  • @Nitish I can embed ViewControllerA in navigationController,I already edit my question,I also can segue to ViewControllerA,but I cant get the value in segue in ViewControllerA – ken Mar 12 '18 at 10:35

1 Answers1

0

Assuming that your storyboards looks similar to:

enter image description here

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.

Ahmad F
  • 30,560
  • 17
  • 97
  • 143