我是编码的新手,我需要将注释变成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”,但它没有打印,因此代码中的某些内容必须被破坏,我无法弄清楚是什么。