1
我想爲我的註釋視圖和從解析下載的圖像製作左側標註附件。出於某種原因,與圖像相關的圖像沒有顯示出來,而左側的標註配件是空白的。縮略圖圖像不顯示在MKMapView註釋視圖
這裏是我當前的代碼:
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is ImageAnnotation {
let reuseId = "image"
var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
if anView == nil {
anView = MKAnnotationView(annotation: ImageAnnotation() as MKAnnotation, reuseIdentifier: reuseId)
anView!.canShowCallout = true
} else {
anView!.annotation = ImageAnnotation() as MKAnnotation
}
let cpa = annotation as! ImageAnnotation
anView!.image = UIImage(named: cpa.imageNameI)
let button = UIButton(type: UIButtonType.DetailDisclosure) // button with info sign in it
anView!.rightCalloutAccessoryView = button
anView!.leftCalloutAccessoryView = UIImageView(frame: CGRectMake(0, 0, 59, 59))
return anView
}
return nil
}
func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView) {
if let Annotation = view.annotation as? ImageAnnotation {
if let thumbnailImageView = view.leftCalloutAccessoryView as? UIImageView {
func loadImage() {
let Coordinate = view.annotation?.coordinate
let lat = Coordinate?.latitude
let lon = Coordinate?.longitude
let AnCoordinate = PFGeoPoint(latitude: lat!, longitude: lon!)
let query = PFQuery(className: "ImageAn")
query.whereKey("shoutoutlocation", equalTo: AnCoordinate)
query.findObjectsInBackgroundWithBlock ({(objects:[AnyObject]?, error: NSError?) in
if(error == nil){
_ = objects as! [PFObject]
for object in objects! {
let thumbNail = object["image"] as! PFFile
thumbNail.getDataInBackgroundWithBlock({
(imageData: NSData?, error: NSError?) -> Void in
if (error == nil) {
let Image = UIImage(data:imageData!)
thumbnailImageView.image = Image
}
})
}
}else{
print("Error in retrieving \(error)")
}
})
}
}
}
}
誰能告訴我什麼,我做錯了什麼? 謝謝
請問佔位符圖像名稱僅僅是類的名字? –
林有點困惑。 –
佔位符圖像名稱是您決定添加的任何內容。您應該爲應用的圖片資源添加某種默認圖片,然後在沒有網絡連接從Parse下載數據時顯示該圖片資源。例如,你可以有一個像問號一樣簡單的東西https://www.adagio.com/images5/question_mark.jpg – Russell