1

I want to switch between viewController by using containerViewController. For this I created multiple segues and viewController.

when I run

func segueIdentifierReceivedFromParent(_ identifier: String){
       self.segueIdentifier = identifier
       self.performSegue(withIdentifier: self.segueIdentifier, sender: nil)
}

in it's parent controller file it works fine but when I called it through other controller file it gives error

ContainerViewController: 0x7fd703707b40>) has no segue with identifier 'second''

This is how i called it in other viewController

let vc = ParentViewController()
vc.segueIdentifierReceivedFromParent("second")

Here "second" is the Identifier given to segue in storyBoard

Above code is written in AddTarget of button. So when I tap button I get Error

Kuldeep
  • 4,466
  • 8
  • 32
  • 59
  • You need to set identifier into storyboard please check this link. its may help you. https://stackoverflow.com/a/41887007/5461400 – Harshal Valanda May 09 '18 at 07:07
  • Possibly Related: https://stackoverflow.com/questions/39904328/xcode-where-to-assign-the-segue-identifier/39905378#39905378 – Ahmad F May 09 '18 at 07:12
  • Thank you for your response. but method is working fine when I called it in viewDidLoad of parent view controller – Shivam Trivedi May 09 '18 at 07:15
  • I'm not sure I'd use segueIdentifierReceivedFromParent - just create a segue from the parentview to where you want to traverse. If you want to call a segue in the child view, just call a function in the child view to segue. Job done. – stevenpcurtis May 09 '18 at 08:10

1 Answers1

0

If you are in same a storyBoard then you can simply do this - Take a button in your firstVC and ctrl + drag a segue upto your secondVC. Then click on the segue. (the round thing on between two view controller). -

enter image description here

And set a identifier for that (here about is the identifier, you can give any name for this)-

enter image description here

Here is the code -

@IBAction func UserDetailVC(sender: AnyObject) {
        self.performSegue(withIdentifier: "segueIdentifierName", sender: sender)
    }
Rashed
  • 2,349
  • 11
  • 26