Dmitriy Vinnichuk Dmitriy Vinnichuk - 5 months ago 16
iOS Question

Tableviewcell not displays image | Swift

Admin can add image/text, the content displays, but the image doesnt do it after adding. I need to add text to make image displayed. For example i can add a lots of images, they are in table, but they will not be viewed until admin add some text.
The thing is that i convert image in base64, add to array, and cellForRowAtIndexPath I decode it and add to a 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

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] as String

return cell


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 to make image be displayed immediately?


call self.tableView.reloadData() in func imagePickerController after content.append(newImage) , maybe you forgot it