0
我正在制作一个可折叠的单元格,当单元格被点击时展开和收缩,但是我没有隐藏我的tableView,并给出了func checkHeight()
中的约束条件。这是我的CustomCell类代码:为什么我的textView没有隐藏在我的CustomCell类
class CustomCell: UITableViewCell {
class var expandedHeight: CGFloat { get { return 170 } }
class var defaultHeight: CGFloat { get { return 44 } }
func checkHeight() {
textView.isHidden = (frame.size.height < CustomCell.expandedHeight)
}
override func awakeFromNib() {
super.awakeFromNib()
}
@IBOutlet weak var textView: UITextView!
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
这是我的我的VC的代码,有TableView
var selectedIndexPath: IndexPath?
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let previousIndexPath = selectedIndexPath
if indexPath == selectedIndexPath {
selectedIndexPath = nil
} else {
selectedIndexPath = indexPath
}
var indexPaths : Array<IndexPath> = []
if let previous = previousIndexPath {
indexPaths += [previous]
}
if let current = selectedIndexPath {
indexPaths += [current]
}
if indexPaths.count > 0 {
tableView.reloadRows(at: indexPaths, with: UITableViewRowAnimation.automatic)
}
}
你有没有尝试重新加载表视图? –
您需要重新加载单元格后点击它,以便它可以重新加载新的高度。你可以使用/不使用动画。 – creeperspeak
@TaylorM实际上我的'TableView'不在这个类中,所以我不能在这个类中刷新它。 –