我在TableView中已經有10行了我想要做的是爲我使用的insertRowsAtIndexPaths添加另外10行,但出現錯誤。iOS:使用insertRowsAtIndexPaths在UITableview中插入多行
以下是我使用
-(void)insertDownloadedActions:(NSMutableArray *)dataToAdd
{
__weak CurrentViewController *weakSelf = self;
int64_t delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[weakSelf.tableView beginUpdates];
[weakSelf.dataSource addObjects:dataToAdd];
NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:[weakSelf.dataSource count]-dataToAdd.count-1 inSection:0];
[weakSelf.tableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationTop];
[weakSelf.tableView endUpdates];
});
}
的代碼,但我收到以下錯誤對於
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (20) must be equal to the number of rows contained in that section before the update (10), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).
您只添加一行而不是10 – Abizern
插入該行時,必須同時增加該部分中的行數。 –
如果您從數據源中獲取該數據並將其添加到數據源中,則會自動提取。問題在於,他只是將一個項目插入到他的表格中,而不是將其添加到數據源中的另外10個項目。 – Abizern