masaldana2 masaldana2 - 3 months ago 33
iOS Question

How to segue multiple view controllers programmatically using swift 3.0

I'm getting an error:


has no segue with identifier 'dest1''


and what I did was:


  • route(ctrl+drag) in storyboard viewcontroller -> dest1, viewcontroller -> dest2

  • have an action button in viewController.swift

  • set storyboard ids to "dest1" and "dest2"

    @IBAction func Parameters(_ sender: AnyObject) {
    self.performSegue(withIdentifier: "dest1", sender: nil)
    }

  • Prepare for segue

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    print("0")
    if segue.identifier == "dest1" {
    if let svc = segue.destination as? secondViewController {
    print("1")
    }
    } else if segue.identifier == "dest2" {
    if let svc = segue.destination as? reverbViewController {
    print("2")
    }
    }



What am I missing?

Answer

From your description, you have set storyboard ids to "dest1" and "dest2", whereas you need to set segue identifiers. Click on the segue itself in IB, and set it's property.

Storyboard identifiers are used when creating the view controller using code...

instantiateViewControllerWithIdentifier("myViewController")
Comments