Tableviewcell不显示图像|迅速

时间:2016-05-28 13:21:34

标签: ios swift tableview decode

管理员可以添加图片/文字,内容显示,但添加后图片不会这样做。我需要添加文字才能显示图像。例如,我可以添加大量图像,它们在表中,但在管理员添加一些文本之前不会查看它们。

问题是我在base64中转换图像,添加到数组,以及cellForRowAtIndexPath我解码它并添加到单元格。

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

    }

如何立即显示图像?

1 个答案:

答案 0 :(得分:0)

self.tableView.reloadData()之后func imagePickerController拨打content.append(newImage),也许你忘记了