我正在尝试向我的标注添加一个按钮,以便我可以转换到另一个 View Controller 。然而,标注不会显示附件 View ,我不确定为什么。我从 firebase 获取一些数据并将其输入到正确的数组中,然后将注释与调用一起发布。我不确定为什么按钮没有显示。
此代码发生在 ViewDidLoad(){...}
bookRef.observeSingleEvent(of: .value, with: {snapshot in
if let userDict = snapshot.value as? [String:AnyObject]{
for each in userDict as [String:AnyObject]{
let bookLats = each.value["bookLat"] as! String
let bookLngs = each.value["bookLng"] as! String
let bookTitle = each.value["title"] as! String
let Author = each.value["Author"] as! String
let Comment = each.value["Comment"] as! String
let Genre = each.value["Genre"] as! String
let User = each.value["User"] as! String
let bookPhoto = each.value["bookPhoto"] as! String
let userID = each.value["userID"] as! String
let userLocation = each.value["userLocation"] as! String
let bookRate = each.value["bookRating"] as! String
let userToBePushed = each.value["pushingID"] as! String
self.bookLatArrayDouble.append((bookLats as NSString).doubleValue)
self.bookLngArrayDouble.append((bookLngs as NSString).doubleValue)
self.bookTitlesArray.append(bookTitle)
}
}
for i in 0...(self.bookLatArrayDouble.count-1){
let locationCoordinates = CLLocationCoordinate2D(latitude: self.bookLatArrayDouble[i], longitude: self.bookLngArrayDouble[i])
var point = BookAnnotation(coordinate: locationCoordinates)
point.title = self.bookTitlesArray[i]
self.Map.addAnnotation(point)
}
我也用过这个功能。
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
// If annotation is not of type RestaurantAnnotation (MKUserLocation types for instance), return nil
var annotationView = self.Map.dequeueReusableAnnotationView(withIdentifier: "Pin")
if annotationView == nil{
annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "Pin")
annotationView?.canShowCallout = true
annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
}else{
annotationView?.annotation = annotation
}
return annotationView
}
编辑:请求图像
最佳答案
我犯了一个非常愚蠢的错误...我忘记放入Map.delegate.self
,所以该函数从未被实际调用是有道理的。该按钮现在显示谢谢大家的帮助!
关于ios - 如何向 MapKit CallOuts Swift 3 添加按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42288488/