【发布时间】:2017-04-13 05:22:01
【问题描述】:
我试图在点击显示更多按钮标签后在tableViewCell 中实现动态标签高度需要设置label.numberOfLines = 0。
那么单元格高度和标签高度应该动态增加。
下面是我的代码(当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 否则返回一些静态高度 -
@Bharath 问题修复了吗?
-
我已经实现了行的高度。但是,我仍然遇到了问题。 @Ganesh
-
@Bharath 你在使用 swift 3 吗?然后 tableview.reloadData 它应该是....还检查是否通过放置断点来调用 showMorePressed 动作。
标签: ios objective-c swift3 reactive-cocoa rx-swift