ios - Async With Parse -
i'm building app based around pictures. it's important me retrieve images asyncronously instagram does. understand function...
var query = pfquery(classname: "post") query.findobjectsinbackgroundwithblock { (objects, error) -> void in if let objects = objects as! [pfobjects] { object in objects { objectsarray.append(object) } } }
...is asynchronous. want way load images parse table asynchronously loads images while scrolling.
you should take @ pfimageview's function loadinbackground()
.
for example, if using pftableviewcontroller pftableviewcell, can following
override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath, object: pfobject?) -> pftableviewcell { var cell = tableview.dequeuereusablecellwithidentifier("customcell") as! customtableviewcell! if cell == nil { cell = customtableviewcell(style: uitableviewcellstyle.default, reuseidentifier: "customcell") } if let name = object?["name"] as? string { cell.namelbl.text = name } var initialthumbnail = uiimage(named: "placeholder") cell.imgview.image = initialthumbnail if let thumbnail = object?["photo"] as? pffile { cell.imgview.file = thumbnail cell.imgview.loadinbackground() } return cell }
with pftableviewcell having
class customcell: pftableviewcell { @iboutlet weak var namelbl: uilabel! @iboutlet weak var imgview: pfimageview! }
also reply, can try this:
let userimagefile = userphoto["imagefile"] pffile userimagefile.getdatainbackgroundwithblock { (imagedata: nsdata!, error: nserror!) -> void in if !error { let image = uiimage(data:imagedata) } }
Comments
Post a Comment