gpt4 book ai didi

ios - 解析检索错误的 PFFile

转载 作者:行者123 更新时间:2023-11-30 12:47:43 25 4
gpt4 key购买 nike

我正在尝试根据附加到我从中提取 imageFile 的同一对象的 objectID 检索 PFFile 图像。所有其他细节都被正确拉取(字符串),但是,当我拉取 PFFile 时,会加载该类中的随机图像,通常不是该对象的匹配图像,下面是我如何查询它的代码,我不确定在哪里我的逻辑是错误的。

@objc(mapView:didTapMarker:) func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
if z == 0 {
print("\(marker) tapped")

let lat = marker.position.latitude as Double
let long = marker.position.longitude as Double


let tempMarker = getMarkerForLongAndLat(long: long, lat: lat, markers: markers)
let index = getIndexForMarker(marker: tempMarker)

getInfo(self.markersID[index]) {
PFFile in
self.imageFile?.getDataInBackground(block: { (imageData, error) in
if(imageData != nil) {
self.fullImage = UIImage(data: imageData!)
}
})
self.performSegue(withIdentifier: "playerSegue", sender: nil)
}
}
return true
}


func getInfo(_ markerID : String, completion: @escaping (PFFile) -> Void)
{
self.group.enter()

print("printing")
print(markerLat)
print(markerLong)
print(postsLat)
print(postsLong)
print("A")
let query = PFQuery(className:"Posted")
print("b")
print(markerID)

//query.whereKey("GPS", equalTo: PFGeoPoint(latitude: markerLat, longitude: markerLong))
query.whereKey("objectId", equalTo: "\(markerID)")
query.findObjectsInBackground { (objects, error) in
print("c")
if(error == nil)
{
print("d")

for object in objects!
{


print("made it")
self.imageFile = (object.object(forKey: "ImageFile") as! PFFile?)
self.userofVideo = object.object(forKey: "User") as AnyObject?
self.hour = object.object(forKey: "Hour") as AnyObject?
self.minutes = object.object(forKey: "minutes") as AnyObject?
self.streetName = object.object(forKey: "Location") as AnyObject?

self.tempLat = (object.object(forKey: "GPS")! as AnyObject).latitude as Double
self.tempLong = (object.object(forKey: "GPS")! as AnyObject).longitude as Double
self.currentText = (object.object(forKey: "text")! as Any? as! String?)
self.tempCoordinates = CLLocationCoordinate2D(latitude: self.tempLat! as CLLocationDegrees, longitude: self.tempLong! as CLLocationDegrees)
//print(tempLong)

}

}
else
{
print("didn't make it")
print(error)
}
completion(self.imageFile!)
}
self.group.leave()

}

最佳答案

for 循环内添加getDataInBackground。这是您的代码的快速 swift 3 示例。

   @IBOutlet weak var fullImage : UIImageView!



let imageFile = (object.object(forKey: "ImageFile") as? PFFile)
imageFile?.getDataInBackground (block: { (data, error) -> Void in
if error == nil {
if let imageData = data {
//Here you can cast it as a UIImage or do what you need to
self.fullImage.image = UIImage(data:imageData)
}
}
})

关于ios - 解析检索错误的 PFFile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41411848/

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