Целевая функция не вызывается UIButton - PullRequest
0 голосов
/ 04 декабря 2018

У меня есть пользовательский вынос, который выглядит очень хорошо, например так:

enter image description here

Но по какой-то причине, когда я нажимаю на любую кнопку, целевая функцияне вызывается и не уверен почему.Вот то, что я пытаюсь:

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
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...