swift - Difficulty retrieving Parse Object Field Values -
i able retrieve "project" objects parse core, , "projectname" values returned me , printed log. thought these values update productnames array displayed in tableview. prototype tableview cell defined in dealcell class image , label. when run app, tableview empty. did miss?
my tableview's class:
var productids = [string]() var productnames = [string]() override func viewdidload() { super.viewdidload() self.productids.removeall(keepcapacity: true) self.productnames.removeall(keepcapacity: true) // ask current user's personal list of saved pfobject ids. let ids = pfuser.currentuser()?.objectforkey("accepted") as! nsarray print(ids) // requesting project objects based on ids retrieved. let projectretrieval = pfquery(classname: "project") projectretrieval.wherekey("objectid", containedin: ids [anyobject]) projectretrieval.findobjectsinbackgroundwithblock({ (objects, error) -> void in if let objects = objects { object in objects { //append productnames array retrieved projectnames self.productnames.append(object["projectname"] as! string) // line prints array of product names retrieved. print("projectnames: \(self.productnames)") } } }) } // number of rows func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int { return self.productnames.count; } // assign productnames labels in each cell. func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { let cell = self.tableview.dequeuereusablecellwithidentifier("dealcell", forindexpath: indexpath) as! dealcell cell.productname.text = self.productnames[indexpath.row] return cell }
my print output strange, looks this, getting projectnames successfully:
projectnames: ["personal drone"] projectnames: ["personal drone", "prosthetic limb patent"]
you should refresh tableview method;
self.tableview.reloaddata()
you can put code after findobjectsinbackgroundwithblock callback closure in case;
projectretrieval.findobjectsinbackgroundwithblock({ (objects, error) -> void in if let objects = objects { object in objects { //append productnames array retrieved projectnames self.productnames.append(object["projectname"] as! string) // line prints array of product names retrieved. print("projectnames: \(self.productnames)") } } self.tableview.reloaddata() })
Comments
Post a Comment