【发布时间】:2016-11-19 03:18:57
【问题描述】:
我正在尝试向表格中添加不同的内容,例如图像/文本。 我为这两种类型创建了 2 个自定义 tableViewCells。我有主数组,所有内容都将保存在其中(由于存储在 JSON 中,图像编码为 base64)。
var content = [String]()
var imgCell: ImageTableViewCell = ImageTableViewCell()
var txtCell: TextTableViewCell = TextTableViewCell()
有两个按钮用于添加图像/文本。
@IBAction func textAddButton(sender: AnyObject) {
self.content.append("text")
self.articleTableView.reloadData()
}
在更新表格时,我无法理解如何将数组数据与自定义单元格连接并显示它。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
if content[indexPath.row] == "text" {
return txtCell
}
else {
return imgCell
}
return UITableViewCell()
}
这是自定义单元格。
class TextTableViewCell: UITableViewCell {
@IBOutlet weak var textArticle: UITextView!
}
【问题讨论】:
标签: ios swift uitableview cell tableviewcell