如何将MKannotation变成连接到视图控制器的UI按钮?

时间:2019-06-27 07:17:46

标签: ios swift mkannotation

我是编码的新手,我需要将注释变成UIButton。我的目标是让用户单击该按钮,然后选择另一个与 Google Maps Apple Maps 类似的UIView。

如何编码按钮,以便在单击按钮时显示UIView?

这是我到目前为止所拥有的:

func displayCordinates() {
        ref = Database.database().reference()
        let storageRef = ref.child("waterfountains")

        storageRef.observeSingleEvent(of: .value, with: { snapshot in
            for child in snapshot.children.allObjects as! [DataSnapshot] {
                let annotation = CustomPointAnnotation()
                let dict = child.value as? [String : AnyObject] ?? [:]
                annotation.title = "Water Fountain"
                annotation.tag = dict["url"]
                annotation.coordinate = CLLocationCoordinate2D(latitude: dict["lat"] as! Double, longitude: dict["long"] as! Double)

                self.mapView.addAnnotation(annotation)

                let reuseId = "pin"

                var pinView = self.mapView.dequeueReusableAnnotationView(withIdentifier: reuseId) as? MKPinAnnotationView
                var rightCalloutAccessoryView: UIView!
                if pinView == nil {
                    pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
                    pinView!.canShowCallout = true

                    pinView!.rightCalloutAccessoryView = UIButton(type: .detailDisclosure) as UIButton
                }
                else {
                    pinView!.annotation = annotation

                }
                }
        })

    }




func mapView(MapView: MKMapView!, annotationView: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {

    if control == annotationView.rightCalloutAccessoryView {
        performSegue(withIdentifier: "toUploadScreen", sender: self)
        print("Going to the next VC!")
    }
}

`

它执行了segue之后,应该打印“转到下一个VC”,但它没有打印,因此代码中的某些内容必须被破坏,我无法弄清楚是什么。

0 个答案:

没有答案