正在更新UITableView行和节



我在视图中使用表视图,并且我希望通过不同的事件动态更改每个部分中的行数。我定义了一个数组,通过它我可以用beginUpdates()endUpdates()函数来处理这一问题,在它们之间我使用deleteRows()insertRows(),但当我使用表视图的这几行时,它不会移动,并且会保留前几行。

我以前做过这项工作,效果很好,但现在我不知道为什么不起作用。有人能帮我吗?

代码中beginUpdates((和endUpdates(。

看到这个多节和多行的基本示例,我希望它能帮助你https://medium.com/swift-programming/swift-enums-and-uitableview-sections-1806b74b8138

您可以在UITableView中添加删除行,如下所示:

tableView.beginUpdates()
// Remove existing row
<designatedModel>.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .none)
// Add new row
<designatedModel>.insert(object, at: indexPath.row)
tableView.insertRows(at: [indexPath], with: .none)
tableView.endUpdates()

最新更新