我試圖在點擊顯示更多按鈕標籤後需要設置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