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
}
イメージをすぐに表示させるにはどうすればよいですか? func imagePickerController
で
笑ああ、私のせいで、それを忘れてしまいました。ありがとうございました! –