【发布时间】:2021-10-28 00:17:12
【问题描述】:
我在表格视图单元格中有很多部分,每个部分包含许多单元格。我需要在单击单元格时放大单元格。现在当我单击单元格时,该部分内的所有单元格高度都会发生变化。请帮我解决这个问题
var expandedIndexSet : IndexSet = []
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if expandedIndexSet.contains(indexPath.section) {
return 406
} else {
return 88
}
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
if(expandedIndexSet.contains(indexPath.section)){
expandedIndexSet.remove(indexPath.section)
} else {
expandedIndexSet.insert(indexPath.section)
}
tableView.reloadRows(at: [indexPath], with: .automatic)
}
【问题讨论】:
标签: ios swift uitableview tableview