ios - UITableviewCell 在动态设置高度为零时卡住滚动
问题描述
我有一个 JSON 对象,其中一个键是 interface_id,我想相应地设置单元格高度,当我尝试设置高度 0 时,tableView 在滚动时卡住了。
public func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat{
if (dataArray[indexPath.row] as AnyObject).value(forKey: "interface_id") as! Int == 1{
return 0
}else{
return UITableViewAutomaticDimension
}
}
解决方案
基本上,要使用自我调整大小的单元格,UITableView
您将设置估计的行高,并将 rowHeight 设置为UITableViewAutomaticDimension
. 所以改变行的单元格高度你的代码应该是这样的。
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return 44.0
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if (dataArray[indexPath.row] as AnyObject).value(forKey: "interface_id") as! Int == 1{
return 0
}else{
return UITableViewAutomaticDimension
}
}
推荐阅读
- amazon-web-services - SQS 消息接收器中缺少 MessageAttributes 属性
- python - 如何优化 3 个单独数组上的三重嵌套 for 循环(Python)
- javascript - 加载页面后,如何在我的 c# 程序中恢复通过 cefSharp 调用的 javascript 函数发送的列表?
- javascript - 如何将 props.theme.breakpoints 与 makeStyles 挂钩使用?
- latex - APA6 一位作者乳胶引用不起作用
- swiftui - 如何增加 SwiftUI 选择器中显示的最大行数?
- optimization - Adobe 分析与 adobe 目标的集成
- python - 尝试通过列表传递for循环时出现索引超出范围错误
- rxjs - rxjs:我可以在定义 observable 之前订阅吗?
- typescript - 定义和使用固定数组类型