ios - Swift 1.2 and Parse: Issue with retrieving images to populate PFQueryCollectionViewController -
i'm working on application displays images @ locations. issue following:
when user clicks on location in mapview goes empty collection view. if user pulls refresh, spinner active images not load. however, if user goes mapview , clicks on location again, images loaded in collection view. of course trying images loaded when user first goes collection view.
i think small issue, after hours of trying different various recommendations different sources cannot work properly.
any appreciated.
thank you.
here code pfquerycollectionviewcontroller
:
import uikit class photogridcollectionviewcontroller: pfquerycollectionviewcontroller { var savedpics: [uiimage]? func loadimages() -> pfquery { var query = pfquery(classname: "userphoto") query.orderbydescending("timetaken") return query } override func viewdidappear(animated: bool) { } override func viewdidload() { super.viewdidload() loadimages() } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } /* // mark: - navigation // in storyboard-based application, want little preparation before navigation override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) { // new view controller using segue.destinationviewcontroller. // pass selected object new view controller. } */ // 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 } }
edit: have updated code , bit cleaner, i'm still having exact same issue.
in previous answer used plain old uicollectionviewcontroller
solve issue, after lot of digging figured out how correctly implement pfquerycollectionviewcontroller
.
there must placeholder image in the pfquerycollectionviewcontroller
or images not load when user first loads the pfquerycollectionviewcontroller
.
here bit of code illustrate this:
import uikit import parse import parseui class photocollectionviewcontroller: pfquerycollectionviewcontroller { ... var parseobject: pfobject! var placeholderview: uiview! ... override func viewdidload() { super.viewdidload() if let layout = collectionviewlayout as? uicollectionviewflowlayout { layout.sectioninset = uiedgeinsetsmake(5.0, 10.0, 5.0, 10.0) layout.minimuminteritemspacing = 5.0 } } ... // mark: pfquery override func queryforcollection() -> pfquery { let query = super.queryforcollection() query.wherekey("name", equalto: parseobject!) query.orderbydescending("date") return query } override func collectionview(collectionview: uicollectionview, cellforitematindexpath indexpath: nsindexpath, object: pfobject?) -> pfcollectionviewcell? { let cell = collectionview.dequeuereusablecellwithreuseidentifier("cell", forindexpath: indexpath) as? customcollectionviewcell ... // here must have placeholder image var initialthumbnail = uiimage(named: "thumbnail") cell?.collectionimageview.image = initialthumbnail if let imagefile = object?["image"] as? pffile { cell?.collectionimageview.file = imagefile cell?.collectionimageview.loadinbackground() } return cell } ... }
the answer quite simple, relatively new ios development took time figure out. necessity placeholder image applies both pfquerycollectionviewcontroller
, pfquerytableviewcontroller
.
Comments
Post a Comment