I'm working on a Parse query that pulls geo-based names and photos then loading them onto a table view. The first part of the query is coming through without an issue. I'm stuck on the second part of pulling/loading photos.
I could be going wrong with a missing call for the images in queryForTable method. Here I've tried includeKey (which failed as it's not a pointer to another object); I've also called for images, using getDataInBackgroundWithBlock. In each instance, I would then try loading the queried objects onto table view with a line like cell.imageData.image = photo.
But differing SO accounts also indicate that the call could go in the tableView method, which is what I have below. I've combed through SO, Parse.com and other resources, but I haven't come across a solution yet. Hoping someone can help:
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!, object: PFObject?) -> Stores! {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! Stores
if let object = object {
let Name = object.valueForKey("Name") as? String
cell.storeList.text = Name
let photo = object.objectForKey("Photos") as? PFFile
photo?.getDataInBackgroundWithBlock {(imageData: NSData!, error: NSError!) -> Void in
if error == nil {
let image = UIImage(data: imageData)
cell.storeImage.file = photo
}
}}
return cell as Store
What finally worked for me was placing the file property within the call as such:
cell.imageView.loadInBackground {(image: UIImage!, error: NSError!) -> Void in
if error == nil {
cell.imageView.file = object!.objectForKey("Photos") as? PFFile
}
A revisit to Parse docs showed that it's '.file,' not '.image'. Also, I went with 'loadInBackground', as opposed to 'loadInBackgroundWithBlock', for an asynchronous call. Hope this can help someone who's puzzled over the same issue.
Thanks to @BHendricks, @ericgu, @danh for sharing their views! Trying out all your suggestions definitely brought me steps closer to my answer.