如何在 Swift 中扩展 Table View Cell 的高度?

How to expand the height of a Table View Cell in Swift?

我有一个 TableViewController 并且想在按下按钮时更改我的其中一个静态单元格的 height。我为我的手机创建了一个插座:

@IBOutlet var myCell: UITableViewCell!

问题是,我没有 属性 的身高,所以我可以 s.th。像这样:

@IBAction func btnClick(sender: UIButton) {
    myCell.rowHeight = 200
}

我知道有一种方法叫做:

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    ...
}

但是当我按下我的 UIButton 时如何触发这个方法?

tableView.beginUpdates() 后跟 tableView.endUpdates() 触发委托方法的调用,如 tableView:heightForRowAtIndexPath:

所以你可以这样做:

var height = 100

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return height
}

@IBAction func btnClick(sender: UIButton) {
    tableView.beginUpdates()
    height = 200
    tableView.endUpdates()
}