Reputation: 1
I am a newbie at Swift as well as Stackoverflow, and I was wondering if there is a way to import data from my plist to detailCalloutAccesoryView in the same manner as I import to "title" and "subtitle" in my map annotation callouts? This way, I could avoid having to make my own custom map annotation, and rather use the built-in features of MapKit.
I am calling my variables to title and subtitle like this:
var myData: NSArray?
if let path = NSBundle.mainBundle().pathForResource("myData", ofType: "plist") {
myData = NSArray(contentsOfFile: path)
}
if let items = myData {
for item in items {
let lat = item.valueForKey("Latitude") as! Double
let long = item.valueForKey("Longitude") as! Double
let myAnnotation = Mydata(value1: "Value1", value2: "Value2", value3: "Value3", latitude: lat, longitude: long)
// Define "Value1 to be shown as title in Callout
myAnnotation = item.valueForKey("Value1") as? String
// Define "Value2 to be shown as subtitle in Callout
myAnnotation.subtitle = item.valueForKey("Value2") as? String
annotations.append(myAnnotation)
}
}
return annotations
}
By now, I am just showing the same value in all annotations for detailCalloutAccessoryView in the place of subtitle using the following piece code:
let detailAccessory = UILabel(frame: CGRectMake(0,0,50,30))
detailAccessory.text = "Value3" // Obviously, shows constant value for all annotations
detailAccessory.font = UIFont(name: "Verdana", size: 10)
pinView?.detailCalloutAccessoryView = detailAccessory
Please, do not let my ignorance annoy you...
Upvotes: 0
Views: 614
Reputation: 4085
You will need to implement func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? delegate method. In there you can customize detailCalloutAccessoryView.
For detailed explanation refer to https://developer.apple.com/videos/play/wwdc2015/206/
Upvotes: 1