I have problem like this - unsolved problem. My custom Annotation View button is not work when I click.
My code:
var confirm: MKAnnotationView = MKAnnotationView()
func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView) {
let annotation = view.annotation as! MapAnnotation
let calloutSize: CGSize = CGSizeMake(250, 100)
confirm = MKAnnotationView(frame: CGRect(x: -calloutSize.width/2, y: -calloutSize.height, width: calloutSize.width, height:calloutSize.height))
confirm.layer.cornerRadius = 10.0
confirm.backgroundColor = UIColor(red: 243/255.0, green: 98/255.0, blue: 35/255.0, alpha: 1.0)
confirm.alpha = 0.9
confirm.userInteractionEnabled = true
let phoneButton = UIButton(frame: CGRectMake(0, 70, 200, 30))
phoneButton.backgroundColor = UIColor.redColor()
phoneButton.addTarget(self, action: "callToNumber:", forControlEvents: .TouchUpInside)
confirm.addSubview(phoneButton)
view.addSubview(confirm)
}
func mapView(mapView: MKMapView, didDeselectAnnotationView view: MKAnnotationView) {
confirm.removeFromSuperview()
}
My target function
func callToNumber(sender: UIButton!){
print("GO!!!")
}
But it doesn't print! If I put my view in viewDidLoad()
its work fine! I think @callToNumber
doesn't work because MKAnnotationView intercept it. How can I solve my problem?