ios - Update Custom UITableViewCell UILabel after asynchronous Parse query -


can't think of name question...if can think of better one, please feel free edit :)

i building ios app using swift , parse.com.

in app, have main pfquerytableviewcontroller loads data parse cloud custom uitableviewcells.

one of values want label on cells takes while parse return , getting using findobjectsinbackgroundwithblock().

in cellforrowatindexpath when i'm loading table, have following code:

// set cells each row of table override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath, object: pfobject?) -> pftableviewcell? {      var cell: customtableviewcell = tableview.dequeuereusablecellwithidentifier("mycell", forindexpath: indexpath) as! customtableviewcell      // course object objectid hand getcoursegrade function     var anobjectid: string = object!.objectid!      cell.setcell(name: object!["objectname"] as! string, code: object!["objectcode"] as! string, grade: getobjectgrade(anobjectid))      return cell  } 

in code above, calling function called getobjectgrade pass value across setcell() function sets customtableviewcells builds uitableview runs below (simplified):

func getobjectgrade(objectidstring: string) -> float {      // set starting value of objectgrade     var objectgrade: float = -1      //...i set pfquery      query?.findobjectsinbackgroundwithblock({ (objects: [anyobject]?, error: nserror?) -> void in          //...here retrive value need parse --> valuefromparse          objectgrade = valuefromparse      })      return objectgrade  } 

now, aware not work...obviously code not wait findobjectsinbackgroundwithblock() code run , returns objectgrade before has been updated.

my question: how set value of label of cell once findobjectsinbackgroundwithblock() code section complete?

solved! moved "getobjectgrade" function customtableviewcell file , called there. :) if has issue , needs help, comment , i'll try :)


Comments