我想添加一個按鈕到我的標註,以便我可以轉換到另一個視圖控制器。然而,標註不會顯示附件視圖,我不確定原因。我從firebase中獲取一些數據並將其提供給適當的數組,然後將註釋與註釋一起發佈。我不知道爲什麼按鈕沒有顯示出來。如何添加一個按鈕到MapKit CallOuts Swift 3
這段代碼使用中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
}
編輯:imgage要求
當我使用此代碼時,它沒有顯示按鈕。只有帶標題但沒有按鈕的標註 –
您可以捕獲標註附件的圖像嗎?是否在標註附件的右側留出空白區域? –
我添加了一張照片。它沒有留下任何空間。 –