将单元格插入 Table 视图后调用哪个方法

Which method call's after inserting cell into Table View

我对将单元格插入 table 视图有点困惑。

当我调用 tableView.insertRows(at: [indexPath], with: .left) tableView 后不会立即更新,在调用的函数中。我认为它调用了一些相关的委托和数据源方法,但是是哪些?

此外,我看到有些人用 tableView.beginUpdates()tableView.endUpdates() 调用 insertRows。如果没有这两种方法发生更新,为什么我们需要这样做?

numberOfRows && cellForRowAt 在你插入时被调用,你需要开始和结束更新以防止后续调用 numberOfRows 以防你大量调用插入/删除以避免异常添加/删除后更新前的行数/节数不相等

现在推荐使用

https://developer.apple.com/documentation/uikit/uitableview/2887515-performbatchupdates

里面

https://developer.apple.com/documentation/uikit/uitableview/1614908-beginupdates

将调用 Tableview DataSource 方法,开始一系列方法调用,插入、删除或 select 行和 table 视图的部分,您需要调用 beginUpdates() 其次是 endUpdates()

Apple's documentation