Ios 在插入/删除行后获取UITableView内容大小
我想实现Ios 在插入/删除行后获取UITableView内容大小,ios,swift,uitableview,Ios,Swift,Uitableview,我想实现tableViewCell被选中,然后插入一些行。再次选择,然后删除这些行。方法如下: func animateRows(tableView: UITableView, insert: Bool, indexPaths: [IndexPath]) { tableView.beginUpdates() if (insert) { tableView.insertRows(at: indexPaths, with: .fade)
tableViewCell
被选中,然后插入一些行。再次选择,然后删除这些行。方法如下:
func animateRows(tableView: UITableView, insert: Bool, indexPaths: [IndexPath]) {
tableView.beginUpdates()
if (insert) {
tableView.insertRows(at: indexPaths, with: .fade)
} else {
tableView.deleteRows(at: indexPaths, with: .fade)
}
tableView.endUpdates()
print(tableView.contentSize)
tableView.reloadData()
print(tableView.contentSize)
}
这种方法效果很好。我想在插入或删除操作结束后获取contentSize
。然后重置tableView的内容大小。但我找到的唯一方法是在调用tableView.reloadData()
contentSize之后进行更新。但我觉得不合适。还有其他好的解决办法吗
编辑:
不管怎样,您对UITableView的contentSize做了什么
我需要
contentSize
使tableView
高度适合内容。实际上,我的tableView是UIScrollView的一个子视图。我需要tableView
始终显示所有行。然后正确地布局scrollView
contentSize
。您如何处理UITableView的contentSize?我需要contentSize来调整tableView
框架的大小,使其适合内容。请参阅有关编辑的详细信息。谢谢。请尝试以下解决方案: