Search code examples
iosswiftseguemkannotationviewpresentviewcontroller

Is it possible to pass data from MKAnnotation without using a segue and just presenting a View Controller?


For some strange reason, Xcode doesn't recognize my segue when I create it and use performSegueWithIdentifier("Details", sender: self).

enter image description here

But I was able to find a way around this by presenting the view controller with this:

let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("DetailsViewController") as! UIViewController

self.presentViewController(viewController, animated: true, completion: nil)

How can I pass data from the MKAnnotationView, to the new details view if I'm not using a segue? (func prepareForSegue requires a segue to pass data right?)


Solution

  • // You have to make object of that DetailViewController(Class Name) rather than viewController

    let viewController:UIViewController = storyboard.instantiateViewControllerWithIdentifier("DetailsViewController") as! DetailViewController
    

    // Then you can access variable of DetailsViewController Like This:

    viewController.parameter = whatever

    self.presentViewController(viewController, animated: true, completion: nil)