动态 TableViewCell | Swift
Dynamic TableViewCell | Swift
我有 2 个自定义单元格:1 个用于图像,2 个用于文本(使用标签显示)。
我希望文本单元格是动态高度,具体取决于文本大小。
将标签行设置为 0,使用顶部、左侧和右侧约束,但是当我将信息添加到数组时,重新加载它 - 然后 table 什么都不显示。
同样在 viewDidLoad 中编码为:
articleTableView.estimatedRowHeight = 150
articleTableView.rowHeight = UITableViewAutomaticDimension
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
}
else{
let cell = self.articleTableView.dequeueReusableCellWithIdentifier("Image Cell", forIndexPath: indexPath) as! ImageTableViewCell
cell.imageArticle.image = decodedImage
}
return UITableViewCell()
}
这里有什么问题?
你需要return cell
而不是return UITableViewCell()
我有 2 个自定义单元格:1 个用于图像,2 个用于文本(使用标签显示)。 我希望文本单元格是动态高度,具体取决于文本大小。 将标签行设置为 0,使用顶部、左侧和右侧约束,但是当我将信息添加到数组时,重新加载它 - 然后 table 什么都不显示。 同样在 viewDidLoad 中编码为:
articleTableView.estimatedRowHeight = 150
articleTableView.rowHeight = UITableViewAutomaticDimension
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
}
else{
let cell = self.articleTableView.dequeueReusableCellWithIdentifier("Image Cell", forIndexPath: indexPath) as! ImageTableViewCell
cell.imageArticle.image = decodedImage
}
return UITableViewCell()
}
这里有什么问题?
你需要return cell
而不是return UITableViewCell()