使用uiimageview定制tableviewcell的高度

时间:2015-10-11 08:22:51

标签: swift uitableview

我有一个uitableview,它有一个uiimageview。它的高度和宽度(总是正方形)是通过在故事板中设置的自动布局计算得出的,并且工作正常。但是当我运行我的应用程序时,tableviewcell的高度没有更新。我尝试使用以下代码来修复它:

tblvwPosts?.rowHeight = UITableViewAutomaticDimension
tblvwPosts?.estimatedRowHeight = 300

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCellWithIdentifier("HomeTableViewCell", forIndexPath: indexPath) as! HomeTableViewCell

    cell.setNeedsUpdateConstraints()
    cell.updateConstraintsIfNeeded()

    return cell
}

但是在添加了上面的代码后,tableviewcell的高度变为44px。 顺便说一句,我希望有一个类似于instagram / facebook的行,其中将有一个宽度/高度等于设备宽度的方形图像,下面会有一些标签和按钮。

问候
的Pankaj

2 个答案:

答案 0 :(得分:0)

如果您有自定义单元格,则可以使用此方法将单元格行高度强制为自定义值;

self.tableView.rowHeight = 100.0

或者您可以使用此代码更改值;

{{1}}

答案 1 :(得分:0)

在tableVC的viewDidLoad中,尝试将估计高度设置为情节提要中的高度,然后将其重置为自动尺寸

override func viewDidLoad(){
    super.viewDidLoad
    tableView.estimatedRowHeight = tableView.rowHeight
    tableView.rowHeight = UITableViewAutomaticDimention
}
相关问题