繁体   English   中英

如何在Swift中扩大表格视图单元格的高度?

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

我有一个TableViewController并且想在按下按钮时更改一个静态单元格的height 我创建了单元的出口:

@IBOutlet var myCell: UITableViewCell!

问题是,我没有物业高度,所以我可以这样做。 像这样:

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

我知道有一个方法叫做:

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

但是,当我按下UIButton时如何触发此方法?

tableView.beginUpdates()后跟tableView.endUpdates()触发对诸如tableView:heightForRowAtIndexPath:类的委托方法的调用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()
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM