2016-05-28 97 views
0

管理員可以添加圖像/文本,內容顯示,但圖像添加後不會執行。我需要添加文字才能顯示圖像。例如,我可以添加大量圖像,它們在表格中,但直到管理員添加一些文本後才能查看它們。Tableviewcell不顯示圖像| Swift

的事情是,我轉換圖片用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 

    } 

如何讓圖像立即顯示?

回答

0

呼叫self.tableView.reloadData()func imagePickerControllercontent.append(newImage)後,也許你忘了

+0

哦哈哈,我的錯。謝謝! –