ios - 目标函数未被调用 UIButton
问题描述
我有一个看起来很好的自定义标注,如下所示:
但是由于某种原因,当我点击任一按钮时,没有调用目标函数,也不知道为什么。以下是我正在尝试的:
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
if view.annotation is MKUserLocation
{
return
}
let calloutAnnotation = view.annotation as! StopAnnotation
selectedStopAnnotation = calloutAnnotation
let calloutView = UIView(frame: CGRect(x: 0, y: 0, width: 147, height: 155))
calloutView.backgroundColor = .darkGray
let fromButton = UIButton(frame: CGRect(x: 22.0, y: 20.0, width: 103.0, height: 44.0))
fromButton.backgroundColor = .white
fromButton.setTitle("+ From", for: .normal)
fromButton.setTitleColor(.darkGray, for: .normal)
fromButton.addTarget(self, action: #selector(self.fromButtonAction), for: .touchUpInside)
calloutView.addSubview(fromButton)
let toButton = UIButton(frame: CGRect(x: 22.0, y: 91.0, width: 103.0, height: 44.0))
toButton.backgroundColor = .white
toButton.setTitle("+ To", for: .normal)
toButton.setTitleColor(.darkGray, for: .normal)
toButton.addTarget(self, action: #selector(self.toButtonAction), for: .touchUpInside)
calloutView.addSubview(toButton)
calloutView.center = CGPoint(x: view.bounds.size.width / 2, y: -calloutView.bounds.size.height*0.52)
view.addSubview(calloutView)
mapView.setCenter((view.annotation?.coordinate)!, animated: true)
}
@objc func fromButtonAction(sender: UIButton) {
fromTextField.text = selectedStopAnnotation.title
}
@objc func toButtonAction(sender: UIButton) {
toTextField.text = selectedStopAnnotation.title
}
解决方案
推荐阅读
- r - 删除每个单元格内新行中的重复观察
- flutter - FLUTTER 如何在附加的法师中创建设计
- sql - 反向Mysql查询
- listview - SatggeredGridview Flutter 分页
- r - 提取/访问嵌入在 PDF 中的 XML 文件
- python - 使用 AES-128 的图像加密
- java - 使用 txt 文件填充多列 ListView (Android)
- reactjs - 如何在测试中避免 react.createElement 错误
- php - 高级自定义字段重复器正在正确返回除图像之外的所有内容
- c# - Net Core 2.2 到 Net Core 3.1 迁移错误