[英]Table view row height doesn't work in iOS
I would like to change dynamically the height of the selected row.我想动态更改所选行的高度。
The documentation says heightForRowAtIndexPath:
is the best way to do so.文档说heightForRowAtIndexPath:
是最好的方法。
I got here so far.我到这里为止。 The tap is detected but the row height doesn't change:检测到水龙头,但行高不会改变:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
func tableView(tableView: UITableView, heightForRowAt: IndexPath) -> CGFloat {
return 490.0
}
// print("helloworld")
}
You don't implement the heightForRowAt:
method inside the didSelectRowAt:
method.您没有在didSelectRowAt:
方法中实现heightForRowAt:
didSelectRowAt:
方法。 You need to update your data model when the row is selected and then tell the table to reload that one row.您需要在选择行时更新数据模型,然后告诉表重新加载该行。 Then your implementation of heightForRowAt:
returns the appropriate height for the given indexPath based on your data model.然后您的heightForRowAt:
实现根据您的数据模型返回给定 indexPath 的适当高度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.