ios - 如何更新tableView单元格高度
问题描述
按下按钮后,我想更新我的单元格高度,所以 atm 我使用了这个闭包并在我的按钮方法中调用他,但不工作):
我的viewDidLoad():
tableView.estimatedRowHeight = 238.0
tableView.rowHeight = 238.0
我的关闭尝试在按下按钮后更改单元格高度
cellClosureHeight = { [weak self] in
self?.tableView.beginUpdates()
self?.tableView.estimatedRowHeight = 118.0
self?.tableView.rowHeight = 118.0
self?.tableView.endUpdates()
}
我的细胞初始化
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch productCells[indexPath.row] {
case .popCorn(let viewModel):
let cell = tableView.dequeueReusableCell(
withIdentifier: TableViewCells.popCornOrder.identifier,
for: indexPath
) as! ProductTableViewCell
cell.set(viewModel: viewModel)
return cell
case .barWater(let viewModel):
let cell = tableView.dequeueReusableCell(
withIdentifier: TableViewCells.barWaterOrder.identifier,
for: indexPath
) as! ProductTableViewCell
cell.set(viewModel: viewModel)
return cell
}
}
解决方案
没有动画
tableView.reloadData()
动画
tableView.beginUpdates()
let indexPaths = [IndexPath.init(row: 0, section: 0)] //the cells you want to update
tableView.reloadRows(at: indexPaths, with: .automatic)
tableView.endUpdates()
推荐阅读
- jquery - 如何在月份编号的文本中显示月份
- python - 通过正则表达式更新数据框下的列
- reactjs - 如何将参数传递给 createAsyncThunk?
- scala - Intellij IDEA 无法解析隐含符号(scala tagless final)
- javascript - 除非我真正查看网页,否则 Selenium 将无法工作(也许是 JavaScript 的反爬虫机制?)
- java - 安装詹金斯,无法在 Windows 10 中打开端口 8080
- sql - SQL 列比较
- xaml - 模拟器在 Xamarin Forms 上显示空白屏幕问题
- javascript - Ramda 数组到多参数函数
- git - 为什么 .gitconfig [includeIf] 不起作用?