我有这样的问题 - unsolved problem。单击时,我的自定义注释视图按钮不起作用。
我的代码:
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()
}
我的目标函数
func callToNumber(sender: UIButton!){
print("GO!!!")
}
但它不会打印!如果我把我的观点放在viewDidLoad()
它的工作正常!我认为@callToNumber
不起作用,因为MKAnnotationView会拦截它。我怎样才能解决我的问题?