I would like to work with an annotation once it's clicked. I've looked it up on the documentation of Apple and I did googled but I can not find why this is any different than how it should be done.
Basically; I don't get a println("Pin clicked");
Why not?
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView!
{
if !(annotation is MKPointAnnotation) {
return nil
}
let reuseId = "test"
var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
if anView == nil {
anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
anView.canShowCallout = true
}
else {
anView.annotation = annotation
}
return anView
}
func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!)
{
println("Pin clicked");
}
func setAnnotationPinOnMap(annotation : NSManagedObject)
{
var subject: AnyObject? = annotation.valueForKey("subject")
var desc: AnyObject? = annotation.valueForKey("desc")
var langitude: AnyObject? = annotation.valueForKey("langitude")
var longitude: AnyObject? = annotation.valueForKey("longitude")
println(annotation);
let pin = MKPointAnnotation()
let location = CLLocationCoordinate2D(
latitude: longitude as CLLocationDegrees,
longitude: langitude as CLLocationDegrees
)
println(location.longitude, location.latitude)
pin.setCoordinate(location)
pin.title = subject as String!
pin.subtitle = desc as String!
println( pin.coordinate.longitude)
viewForAnnotation(pin);
mapView.addAnnotation(pin)
}
I have imported map kit and included the map view delegate.