Admin kann Bild/Text hinzufügen, der Inhalt wird angezeigt, aber das Bild tut es nicht nach dem Hinzufügen. Ich muss Text hinzufügen, um das Bild anzuzeigen. Zum Beispiel kann ich eine Menge Bilder hinzufügen, sie sind in der Tabelle, aber sie werden nicht angezeigt, bis Admin einen Text hinzufügen.Tableviewcell zeigt Bild nicht an | Swift
Die Sache ist, dass ich Bild in base64 umwandle, zum Array hinzufüge, und cellForRowAtIndexPath ich entziffere es und füge zu einer Zelle hinzu.
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
}
Wie kann ich das Bild sofort anzeigen lassen?
oh lol, meine Schuld. Danke! –