How to retrieve a image from Parse?

▼魔方 西西 提交于 2020-01-03 05:29:12

问题


I'm trying to get an image from a parse server that is hosted on Heroku. So far I have gotten the Text values but the images are the only problem.

Here is my code so far:

// Getting Info from servers
    let dataQ = PFQuery(className: "message")
    dataQ.findObjectsInBackground { (objects: [PFObject]?, error: Error?) -> Void in

        if error == nil {
            for object in objects! {
               self.sentFromLabel.text = object["sender"] as? String

                // Get Image from server
                object["Picture"].getDataInBackgroundWithBlock
            }
        } else {
            print(error)
        }
    }

So far when I use .getDataInBackgroundWithBlock it gives me an error. I have no clue why. What is the Swift 3 version to allow me to get an image from the server?


回答1:


Here is a swift 3 example!

@IBOutlet weak var fullImage : UIImageView!

  //place this in your for loop
  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)
                         }
          }
    })


来源:https://stackoverflow.com/questions/41578120/how-to-retrieve-a-image-from-parse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!