swift - How get images in Parse, Cell name works but images don't load -
i can load images parse, have code name, want show images @ cell, don't load images!
// import uikit import parse import bolts class lojasviewcontroller: uiviewcontroller, uitableviewdelegate { var parsedata = [pfobject]() var parseimages = [pffile]() @iboutlet weak var saloestableview: uitableview! override func viewdidload() { super.viewdidload() // retrieving parse information var query = pfquery(classname:"saloes") query.orderbyascending("nome") query.findobjectsinbackgroundwithblock { (objects: [anyobject]?, error: nserror?) -> void in if error == nil { // find succeeded. println(objects!.count) // found objects if let objects = objects as? [pfobject] { self.parsedata = objects println(self.parsedata.count) self.saloestableview.reloaddata() object in objects { println(object["nome"]) println(object["cidade"]) println(object["imagemcelula"]) println(object["endereco"]) println(object["geoponto"]) println(object["telefone"]) println(object["celular"]) println(object["texto"]) println(object["imagem1"]) println(object["imagem2"]) println(object["imagem3"]) println(object["imagem4"]) println(object["imagem5"]) println(object["imagem6"]) println(object["imagem7"]) println(object["imagem8"]) println(object["imagem9"]) } } } else { // log details of failure println("error: \(error!) \(error!.userinfo!)") } } } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } // esconde statusbar override func prefersstatusbarhidden() -> bool { return true } @ibaction func voltarbutton(sender: anyobject) { self.dismissviewcontrolleranimated(true, completion: nil) } func loaddata () { } // mark: - table view data source ____________________________________ func numberofsectionsintableview(tableview: uitableview!) -> int { return 1 } func tableview(tableview: uitableview!, numberofrowsinsection section: int) -> int { return parsedata.count } func tableview(tableview: uitableview?, cellforrowatindexpath indexpath: nsindexpath?) -> uitableviewcell? { let cell:saloestableviewcell = tableview!.dequeuereusablecellwithidentifier("cell", forindexpath: indexpath!) as! saloestableviewcell cell.nomesalao.text = parsedata[indexpath!.row]["nome"] as? string let imagemcelula = parsedata[indexpath!.row]["imagemcelula"] as! pffile return cell } func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { } override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject!) { } }
you can parse object using findobjectsinbackgroundwithblock
. once have parse object image, need download actual file calling getdatainbackgroundwithblock
.
here code:
i updated parseimages array of nsdata.
i implemented getdatainbackgroundwithblock
.
i assigned imagemcelula
uiimage image retrieved parse.
let me know how works
import uikit import parse import uikit import parse import bolts class lojasviewcontroller: uiviewcontroller, uitableviewdelegate { var parsedata = [pfobject]() var parseimages: [nsdata] = [] @iboutlet weak var saloestableview: uitableview! override func viewdidload() { super.viewdidload() // retrieving parse information var query = pfquery(classname:"saloes") query.orderbyascending("nome") query.findobjectsinbackgroundwithblock { (objects: [anyobject]?, error: nserror?) -> void in if error == nil { // find succeeded. println(objects!.count) // found objects if let objects = objects as? [pfobject] { self.parsedata = objects println(self.parsedata.count) self.saloestableview.reloaddata() object in objects { object.getdatainbackgroundwithblock({ (parseimagedata, error) -> void in if (error == nil) { let thatimagedata: nsdata = parseimagedata parseimages.append(thatimagedata) println(object["nome"]) println(object["cidade"]) println(object["imagemcelula"]) println(object["endereco"]) println(object["geoponto"]) println(object["telefone"]) println(object["celular"]) println(object["texto"]) println(object["imagem1"]) println(object["imagem2"]) println(object["imagem3"]) println(object["imagem4"]) println(object["imagem5"]) println(object["imagem6"]) println(object["imagem7"]) println(object["imagem8"]) println(object["imagem9"]) } else { println("failed load images") } } } } else { // log details of failure println("error: \(error!) \(error!.userinfo!)") } } } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } // esconde statusbar override func prefersstatusbarhidden() -> bool { return true } @ibaction func voltarbutton(sender: anyobject) { self.dismissviewcontrolleranimated(true, completion: nil) } func loaddata () { } // mark: - table view data source ____________________________________ func numberofsectionsintableview(tableview: uitableview!) -> int { return 1 } func tableview(tableview: uitableview!, numberofrowsinsection section: int) -> int { return parsedata.count } func tableview(tableview: uitableview?, cellforrowatindexpath indexpath: nsindexpath?) -> uitableviewcell? { let cell:saloestableviewcell = tableview!.dequeuereusablecellwithidentifier("cell", forindexpath: indexpath!) as! saloestableviewcell cell.nomesalao.text = parsedata[indexpath!.row]["nome"] as? string let imagemcelula = uiimage(data: parseimages[indexpath!.row]) return cell } func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { } override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject!) { } }
Comments
Post a Comment