Search code examples
swiftswift3modalviewcontrollerpresentviewcontroller

How can I add a segue identifier to a programmatically modal transition?


I have a controller which is in the Main storyboard. When I click on a button, I call the displayBorneDetailsAction() action, it presents a modal view from another storyboard.

I would add a Segue identifier when I present my modal to pass data from my main view controller to my modal view controller (with prepareForSegue), but I don't know how to do it.

I tried to use performSegue(withIdentifier:), but it doesn't present the modal in the same way.

@IBAction func displayBorneDetailsAction(_ sender: Any) {
    // open the modal of a borne
    let storyboard : UIStoryboard = UIStoryboard(name: "Borne", bundle: nil)
    let vc: BorneVC = storyboard.instantiateViewController(withIdentifier: "BorneVC") as! BorneVC

    let navigationController = UINavigationController(rootViewController: vc)
    navigationController.modalPresentationStyle = UIModalPresentationStyle.overFullScreen
    navigationController.edgesForExtendedLayout = []

    self.present(navigationController, animated: true, completion: nil)
}

Solution

  • You cannot add an identifier to a programmatical segue, since you are able to access the instance of the controller that is being presented. Simply do anything you want with the controller in the function where you present it.