简体   繁体   中英

Unable to perform segue due to no segue with identifier error

How can I do so the user gets taken to a custom view controller when he/she taps on "okay" button on alert?

I have a main controller -> navigation controller -> second view controller.

Main View Controller has a segue "mainStoryBoard" The alert gets generated on the second view controller.

This is what I have

let alertController = UIAlertController(title: "title", message: "message",     preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: { action
    in self.performSegue(withIdentifier: "mainStoryBoard", sender: self)
}))

present(alertController, animated: true, completion: nil)
return

The error I am getting is the following:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver () has no segue with identifier 'mainStoryBoard'

I have set the identifier to 'mainStoryBoard' and still no luck.

Any guidance will be greatly appreciated.

Thanks to @MikeG's guidance I was able to get it to work.

The problem was that I created a segue from the main view controller to the second view controller .

Solution

Create a segue from the second view controller to the main view controller and if you have a navigation controller , create the segue from the second view controller to the navigation controller .

The code remained the same.

How are you loading your main view controller?. Try to instantiate using instantiateviewcontrollerwithidentifier not with alloc init. Still if you are facing this problem then try to clean the project and run.

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