1

I'm working on a map which have some markers and I want to create an info view which will show an image and some text for each marker.

map

So, when I press the info button, it goes to a info view.

map2

I have this on the code:

func mapView(mapView: MKMapView, annotationView: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
    if control == annotationView.rightCalloutAccessoryView {

        performSegueWithIdentifier("showInfo", sender: data)

    }
}

But I want to pass the data from "locations" so I could show a image for each.

I need to do this in Swift.

Thanks a lot.

1

3 Answers 3

4

You should add this method to your class if you do not have and then pass your data to destination view's data.

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "showInfo" {
        let destination = segue.destinationViewController as! YourViewController
        //this will execute before next ViewController's viewDidLoad method
        destination.data = sender
    }
}
0

You have to override prepareForSegue function in your viewController:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

        if "showInfo" == segue.identifier {
           // Then pass your data
           let destController = segue.mapViewController as! YourViewController 
           destController.yourData = sender
        }
    }
0

Connect the info button outlet to your viewcontroller. Then create func as follows:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if "YourSegue" == segue.identifier {
        // Then pass your data
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.