ios - Images not appearing in PFQueryCollectionViewController -


i'm working on iphone app should display images in uicollectionview. images saved on parse cloud, , i'm using subclass of pfquerycollectionviewcontroller make query , display images.

tapping on mkmapview callout triggers segue shows collectionviewcontroller. images not appear in cells first time collectionviewcontroller presented. however, if go mapview, , return collectionviewcontroller, images appear in cells.

how can images appear first time pfquerycollectionviewcontroller presented?

here's code:

class photogridcollectionviewcontroller: pfquerycollectionviewcontroller {  override func viewdidappear(animated: bool) { }  override func viewdidload() {   super.viewdidload() }  override func didreceivememorywarning() {   super.didreceivememorywarning()   // dispose of resources can recreated. }  // mark: uicollectionviewdatasource  override func numberofsectionsincollectionview(collectionview: uicollectionview) -> int {   //#warning incomplete method implementation -- return number of sections   return 1 }  override func collectionview(collectionview: uicollectionview, numberofitemsinsection section: int) -> int {   //#warning incomplete method implementation -- return number of items in section   return self.objects.count }  override func collectionview(collectionview: uicollectionview, cellforitematindexpath indexpath: nsindexpath, object: pfobject?) -> pfcollectionviewcell? {    let cell = collectionview.dequeuereusablecellwithreuseidentifier("venuephotothumb", forindexpath: indexpath) as! photogridcollectionviewcell    if let pfobject = object {     cell.imageview.file = pfobject["imagefile"] as? pffile     cell.imageview.loadinbackground({ (img, err) -> void in       println("download complete")     })   }    return cell }  } 

since i'm using storyboards, pass custom class parseclass setting in attribute inspector:

enter image description here

as can see, i'm using loadinbackground method of pfimageview load images asynchronously, , think problem might caused images being downloaded after cell returned, don't have other ideas. know why images not appearing first time view presented?

my co-developer found answer this. had set placeholder image pfimageviews when configuring cells in cellforitematindexpath. code examples on parse include setting placeholder image, don't required pfquerycollectionviewcontroller work properly. considered aesthetic touch come later.

so answer is: in order images load in cells of pfquerycollectionviewcontroller must provide placeholder image when configuring cells in cellforitematindexpath.

here's code worked:

let placeholder = uiimage(named: "myplaceholderimage")  //an image images.xcassets in xcode project cell.imageview.image = placeholder  if let pfobject = object {     cell.imageview.file = pfobject["image"] as? pffile     cell.imageview.loadinbackground() } 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -