【问题标题】:Dynamic TableViewCell | Swift动态 TableViewCell |迅速
【发布时间】:2016-05-26 13:43:49
【问题描述】:

我有 2 个自定义单元格:1 个用于图像,2 个用于文本(使用标签显示)。 我希望文本单元格是动态高度,具体取决于文本大小。 将标签行设置为 0,使用顶部、左侧和右侧约束,但是当我将信息添加到数组时,重新加载它 - 然后表格什么也不显示。 同样在 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()

}

这里有什么问题?

【问题讨论】:

  • 没有底部约束?
  • 你必须写一些代码,否则我们玩彩票
  • 你要我写什么代码? @AlessandroOrnano
  • 首先 cellForRowAtIndexPath ,然后如果你在标签中使用 sizeToFit ,你也可以发布一些关于所有约束的截图..它太小了
  • @AlessandroOrnano 添加了

标签: swift dynamic tableview cell tableviewcell


【解决方案1】:

你需要return cell 而不是return UITableViewCell()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-18
    • 2021-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多