我试图在点击显示更多按钮标签后需要设置label.numberOfLines = 0
后,在tableViewCell
中实现动态标签高度。动态标签和单元格高度显示更多按钮动作
然后细胞高度和标签高度应该动态增加。
这里是我下面的代码(当tableView
重新加载相同标签的高度以用于重复使用电池)
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: UITableViewCell =
self.tableView.dequeueReusableCell(withIdentifier:
"BTSTableViewCellIdentifier")!
cell.configureWithPost(posts[indexPath.row])
cell.delegate = self
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath:
IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt
indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func configureWithPost(_ postViewModel: BTSTableCellViewModel) {
self.postViewModel = postViewModel
usernameLabel.text = postViewModel.username
detailtextLabel.numberOfLines = 2
detailtextLabel.text = postViewModel.textDetail
}
@IBAction func showmorePressed(_ sender: Any) {
detailtextLabel.numberOfLines = 0;
self.tableView.reload()
}
返回'UITableViewAutomaticDimension'的高度索引路径行按下时ViewMore否则返回一些静态高度 – Dhiru
@Bharath问题修复? –
我已经实现了行的高度。但是,我仍然遇到这个问题。 @Ganesh – Bharath