ios - Tableviewcell not displays image | Swift -
admin can add image/text, content displays, image doesn't after adding. need add text make image displayed. example can add lots of images, in table, not viewed until admin add text.
the thing convert image in base64, add array, , cellforrowatindexpath decode , add cell.
func imagepickercontroller(picker: uiimagepickercontroller, didfinishpickingimage image: uiimage, editinginfo: [string : anyobject]?) { var data = nsdata() data = uiimagepngrepresentation(image)! let base64string = data.base64encodedstringwithoptions(nsdatabase64encodingoptions.encoding64characterlinelength) let newimage = "imagebase64" + base64string content.append(newimage) self.dismissviewcontrolleranimated(true, completion: nil) } func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell{ if content[indexpath.row].rangeofstring("imagebase64") == nil { let cell = self.articletableview.dequeuereusablecellwithidentifier("text cell", forindexpath: indexpath) as! texttableviewcell cell.textarticle.text = content[indexpath.row] string return cell } else{ let cell = self.articletableview.dequeuereusablecellwithidentifier("image cell", forindexpath: indexpath) as! imagetableviewcell let imagestring = content[indexpath.row].stringbyreplacingoccurrencesofstring("imagebase64", withstring: "") let decodeddata = nsdata(base64encodedstring: imagestring, options: nsdatabase64decodingoptions.ignoreunknowncharacters) let decodedimage = uiimage(data: decodeddata!) cell.backgroundcolor = uicolor.clearcolor() cell.imagearticle.image = decodedimage return cell }
how make image displayed immediately?
call self.tableview.reloaddata()
in func imagepickercontroller
after content.append(newimage)
, maybe forgot
Comments
Post a Comment