如何在没有reloadData的情况下使用insertRowsAtIndexPaths IOS

Dab*_*b88 4 uitableview ios

我不明白这个insertRowsAtIndexPaths用法.我需要reloadData为这项工作制作一张桌面视图吗?

如果不进行reloadData应用程序崩溃.

wat*_*n12 5

应用程序崩溃,因为在insertRows调用之前和之后数据源不一致.

例如,如果要插入一个新行,则需要tableView:numberOfRowsInSection:在插入调用之前返回1行.

这是一个展示的例子

self.numberOfRows = self.numberOfRows + 1;
[self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic]; 
Run Code Online (Sandbox Code Playgroud)