Ios 具有“显示更多”按钮动作的动态标签和单元格高度
单击“显示更多”按钮后,我试图在Ios 具有“显示更多”按钮动作的动态标签和单元格高度,ios,objective-c,swift3,reactive-cocoa,rx-swift,Ios,Objective C,Swift3,Reactive Cocoa,Rx Swift,单击“显示更多”按钮后,我试图在tableViewCell中实现动态标签高度。标签需要设置label.numberOfLines=0 然后单元格高度和标签高度应动态增加 下面是我的代码(当tableView重新加载重复使用单元格的相同标签高度时) 您还需要管理RowAtIndexPath的高度: func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
tableViewCell
中实现动态标签高度。标签需要设置label.numberOfLines=0
然后单元格高度和标签高度应动态增加
下面是我的代码(当tableView
重新加载重复使用单元格的相同标签高度时)
您还需要管理RowAtIndexPath的高度:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
在showMore按钮操作中
@IBAction func showmorePressed(_ sender: Any) {
detailtextLabel.numberOfLines = 0;
self.tableView.reloadData()
}
按ViewMore键时,返回索引路径行的高度处的
UITableViewAutomaticDimension
,否则返回一些静态值height@Bharath问题已解决?我已经为行设置了高度。但我还是明白了这个问题@Ganesh@Bharath你用的是swift 3吗?然后tableview.reloadData它应该是…。还要检查是否通过放置断点调用showMorePressed acton。我仍然遇到同样的问题。你能帮我解决这个问题吗?
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
@IBAction func showmorePressed(_ sender: Any) {
detailtextLabel.numberOfLines = 0;
self.tableView.reloadData()
}