正如问题所述,我试图扩展UITableViewCell,当用户选择它以便在该单元格中显示附加信息时。我在这里查看了类似的相关问题,并且已经得到它的工作。该应用程序不会崩溃,单元格会展开,但我不断收到控制台中的约束布局错误。我几乎肯定我得到这些错误,因为当UITableViewCell没有被选中时,它不足以包含额外的标签,即使该标签在被选中之前隐藏。如果有人有建议,或以其他方式完成功能,我会非常感谢他们的帮助。谢谢!展开UITableViewCell以显示选中时的其他文本标签
自定单元,我试图扩大
class ListTableViewCell: UITableViewCell {
@IBOutlet weak var wordLabel: UILabel!
@IBOutlet weak var definitionLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
self.autoresizingMask = UIViewAutoresizing.FlexibleHeight
self.clipsToBounds = true
self.definitionLabel.hidden = true
}
}
的UITableView代码展开一个UITableViewCell选择
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.cellForRowAtIndexPath(indexPath) as! ListTableViewCell
if cell.definitionLabel.hidden == true {
cell.definitionLabel.hidden = false
} else {
cell.definitionLabel.hidden = true
}
currentRow = indexPath.row
tableView.beginUpdates()
tableView.endUpdates()
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if currentRow == indexPath.row {
return UITableViewAutomaticDimension
} else {
return 55.0
}
}
调用'reloadRowsAtIndexPaths'重新加载单元格的高度 – 0yeoj