【发布时间】:2017-02-03 03:53:51
【问题描述】:
要求;
我有一个静态的UITableView,当单击其中一个单元格时,我试图打开一个pickerview。我用heightForRowAt 更改大小,所以当单击cell 时,我需要reload 以更改大小。如果我使用reloadData(),它会完美运行(我想使用reloadRows,所以我可以添加动画)
问题:
当我尝试reloadRows(at..., with: .automatic) 时,行就会消失。如果我 reloadRows 在 viewWillAppear 中没有任何变化,则该行不会消失。
代码:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print(indexPath)
if colorCelllExpandedIndex != nil{
let prev = colorCelllExpandedIndex
colorCelllExpandedIndex = nil
tableView.reloadRows(at: [prev!], with: .automatic)
//tableView.reloadData()
} else {
colorCelllExpandedIndex = indexPath
colorCell.frame.size.height = CGFloat(colorCellExpandedHeight)
tableView.reloadRows(at: [indexPath], with: UITableViewRowAnimation.automatic)
}
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath == colorCelllExpandedIndex {
return CGFloat(colorCellExpandedHeight)
} else {
if indexPath.row == 1 {
return CGFloat(colorCellRegularHeight)
}
return UITableViewAutomaticDimension
}
}
屏幕图像:
【问题讨论】:
标签: ios iphone swift uitableview swift3