【发布时间】:2015-03-24 22:21:55
【问题描述】:
我知道有人可能会回答这个问题,但我还没有找到解决方案。
我正在尝试使用 Swift 通过代码更改静态单元格的高度。我正在使用这种方法
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
但单元格大小不会根据标签的内容而改变。这就是我所拥有的:
@IBOutlet weak var testDetailsLabel: UILabel!
@IBOutlet weak var testDetailsCell: TestDetailsTableViewCell!
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if indexPath.section == 1 && indexPath.row == 0 {
self.testDetailsCell.descriptionLabel?.text = self.test?.details
self.testDetailsCell.setNeedsLayout()
self.testDetailsCell.layoutIfNeeded()
self.testDetailsCell.bounds = CGRectMake(0.0, 0.0, tableView.bounds.width, self.testDetailsCell.bounds.height)
self.testDetailsCell.setNeedsLayout()
self.testDetailsCell.layoutIfNeeded()
let size = self.testDetailsCell.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize) as CGSize!
return size.height + 1
}
return super.tableView(tableView, heightForRowAtIndexPath: indexPath)
}
有人知道是否可以更改静态单元格的高度大小吗?
也许约束是问题所在?我有两侧约束,顶部、底部和高度 >= 约束。
【问题讨论】:
标签: ios uitableview swift ios7