[英]Tableviewcell not displays image | Swift
Admin can add image/text, the content displays, but the image doesn't 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. 关键是我将图像转换为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
}
How do I make the image be displayed immediately? 如何使图像立即显示?
在content.append(newImage)
之后调用func imagePickerController
self.tableView.reloadData()
,也许您忘记了它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.