gpt4 book ai didi

swift - 缩略图图像未显示在 MKMapView 注释 View 中

转载 作者:行者123 更新时间:2023-11-28 06:56:49 25 4
gpt4 key购买 nike

我正在尝试为我的注释 View 和从 Parse 下载的图像制作左侧标注附件。由于某种原因,与图像关联的图像未显示,左侧标注附件为空白。

这是我当前的代码:

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)")
}
})

}
}

}
}

谁能告诉我我做错了什么?谢谢

最佳答案

您需要在分配图像数据后在完成 block 中刷新 View ,或者您可以使用 PFImageView 而不是 UIImageView

PFImageView 包含在 ParseUI 框架中,并在下载文件时自动处理显示占位符图像,然后在准备就绪时更新 View 。

典型用法

// Set placeholder image
thumbnailImageView.image = UIImage(named: "thumbnail_placeholder")

// Set remote image (PFFile)
thumbnailImageView.file = object["image"] as! PFFile

// Once the download completes, the remote image will be displayed
thumbnailImageView.loadInBackground { (image: UIImage?, error: NSError?) -> Void in
if (error != nil) {
// Log details of the failure
println("Error: \(error!) \(error!.userInfo!)")
} else {
// profile picture loaded
}
}

关于swift - 缩略图图像未显示在 MKMapView 注释 View 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33354136/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com