2016-12-31 7 views
0

同じオブジェクトに添付されたobjectIDに基づいてPFFileイメージを取得しようとしていますが、imageFileを取得しています。他のすべての詳細は正しく引っ張られています(文字列)しかし、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() 

} 

答えて

0

forloopgetDataInBackgroundを追加します。ここでは、あなたのコードの迅速な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) 
              } 
             } 
      }) 
関連する問題