Search code examples
iosiphoneswiftmapkitmapkitannotation

Make a segue from map view when annotation is clicked


I am having trouble creating a segue from my Map view to another View Controller. I want the user to click an annotation and have another view controller pop up. I am having trouble creating the segue between the annotation press and the next view controller. I named my segue from the map view to the navigation view Controller 'annotationPress'. Whenever I click the annotations on the map, I get a new view controller that is all black. Any advice would be appreciated.

    func mapView(mapView: MKMapView!, annotationView view: MKAnnotationView!, calloutAccessoryControlTapped control: UIControl!)
    {
//        performSegueWithIdentifier("annotationPress", sender: view)
    }


    override func performSegueWithIdentifier(identifier: String?, sender: AnyObject?) {
        println("segueing...")
        if identifier == "annotationPress"
        {

        }

    }
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "annotationPress"
        {
            println("hello")
            var vc = MapRouteViewController()

        }
    }

enter image description here


Solution

  • You shouldn't override function performSegueWithIdentifier just prepareForSegue

    Also the prepareForSegue method your implementation is wrong (if you are trying to pass some arguments into destination view controller). You need something like this

    let vc = segue.destinationViewController as! MapRouteViewController