1

I am trying to pass data from a map view about an point annotation whenever the right detail accessory is tapped to another view that will display more information about the point annotation that isn't displayed in the callous view. I know I need to use override function prepareForSegue but how do I properly set it up to do what I want. The other information about the point annotation is coming from Parse so I'm assuming I will have to set up a query as well. Please help! Thanks!!!

Trip Phillips
  • 430
  • 1
  • 5
  • 18

2 Answers2

1

You can use NSUserDefaults to pass a value from your map view to another view this way:

func mapView(mapView: MKMapView!, annotationView view: MKAnnotationView!, calloutAccessoryControlTapped control: UIControl!) {

    let title = view.annotation.title
    NSUserDefaults.standardUserDefaults().setObject(title, forKey: "mapTitle")
    performSegueWithIdentifier("mapToCity", sender: self)

}

In your next view you can get values this way:

override func viewDidLoad() {
    super.viewDidLoad()
    let foo1 = NSUserDefaults.standardUserDefaults().objectForKey("mapTitle") as! String
    println(foo1)

}

For more Info check THIS sample project.

Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165
  • This works well for the information about the location that is already there (the title and sub title) but how do I use this method to show extra information I have saved in Parse? – Trip Phillips Aug 06 '15 at 21:34
1

first you call the segue:

performSegueWithIdentifier("segue")

then prepareforsegue:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "segue" {
        let viewController = segue.destinationViewController as! YourViewController
        controller.setPoint = "10"
    }
}

this will set the value before the segue happens. Hope it helps!

DanielEdrisian
  • 716
  • 1
  • 4
  • 17
  • How do I add specific data from Parse to this? I have a lot of information so if I just tell it to get the object in background then it won't know what information I actually want it to get that is specific to that annotation. – Trip Phillips Aug 07 '15 at 04:01