I'm building an app using swift and MapKit. It has several custom point annotations. I would like to display the title above all annotations at any time, by default. Hence they would be all selected. Therefore I could get inspiration from this post and use:
[mapView selectAnnotation:pinView animated:YES]
But I still need to be able to select a pin by clicking on it and get a new mapScope based on this annotation. How could I do it?
If the first solution is not possible, I would use a specific label on each annotation. But then is there a way to hide the annotation title forever?
EDIT:
Here is the code for the custom point annotation:
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
println("viewForAnnotation")
if !(annotation is MKPointAnnotation) {
return nil
}
var seleccion:Bool
let cpa = annotation as! CustomPointAnnotation
let reuseId = cpa.nickName as String
var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
if anView == nil {
anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
anView.canShowCallout = true
// create and add UILabel only when actually creating MKAnnotationView
var nameLbl: UILabel! = UILabel(frame: CGRectMake(-24, 40, 100, 30))
nameLbl.tag = 42
nameLbl.textColor = UIColor.blackColor()
nameLbl.font = UIFont(name: "Atari Classic Extrasmooth", size: 10)
nameLbl.textAlignment = NSTextAlignment.Center
anView.addSubview(nameLbl)
}
else {
anView.annotation = annotation
}
anView.image = cpa.image
if cpa.toBeTriggered == true {
anView.selected = true
}
if let nameLbl = anView.viewWithTag(42) as? UILabel {
nameLbl.text = cpa.nickName
}
return anView
}