gpt4 book ai didi

ios - 断言失败-[UITableView _endCellAnimationsWithContext]

转载 作者:可可西里 更新时间:2023-11-01 04:16:00 25 4
gpt4 key购买 nike

我正在解析一个 xml 文件并将其解析的值放在 TableView 中。 TableView 只有一个部分。但我遇到以下异常:

2013-10-14 15:21:57.250 tableview[6068:907] * Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit/UIKit-2380.17/UITableView.m:909 2013-10-14 15:22:11.227 tableview[6068:907] Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update' ** First throw call stack: (0x33e752a3 0x3bcde97f 0x33e7515d 0x3474aab7 0x35cb0a9f 0x35de6b27 0x6a10f 0x69ce5 0x33dc6037 0x346dc599 0x6b54b 0x3478c0f5 0x33e4a683 0x33e49ee9 0x33e48cb7 0x33dbbebd 0x33dbbd49 0x379702eb 0x35cd1301 0x68bdd 0x68b64) libc++abi.dylib: terminate called throwing an exception

代码是:

/**
The NSOperation "ParseOperation" calls addFiles: via NSNotification, on the main thread which in turn calls this method, with batches of parsed objects. The batch size is set via the kSizeOfEarthquakeBatch constant.
*/
- (void)addFilesToList:(NSArray *)files {

NSInteger startingRow = [self.fileList count];
NSLog(@"STARTING ROW:%d",startingRow);
NSInteger fileCount = [files count];
NSLog(@"FILE COUNT : %d",fileCount);
NSMutableArray *indexPaths = [[NSMutableArray alloc] initWithCapacity:fileCount];
NSLog(@"INDEX PATHS:%@",indexPaths);
for (NSInteger row = startingRow; row < (startingRow + fileCount); row++) {
NSLog(@"into for");

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:0];
NSLog(@"INDEXPAth %@",indexPath);
[indexPaths addObject:indexPath];
}

[self.fileList addObjectsFromArray:files];
NSLog(@"ADD objects");
NSLog(@"FILELIST:%@",self.fileList);

//GETTING EXCEPTION AT THIS LINE

[self.tableview insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationAutomatic];
}


#pragma mark - UITableViewDelegate\

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

// The number of rows is equal to the number of earthquakes in the array.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

return [self.fileList count];
NSLog(@"NUMBER OF ROWS :%d",[self.fileList count]);
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *kFileCellID = @"Cell";
myTableCell *cell = (myTableCell *)[tableView dequeueReusableCellWithIdentifier:kFileCellID];

// Get the specific earthquake for this row.
fileList *file = (self.fileList)[indexPath.row];

[cell configureWithFile:file];
return cell;
}

最佳答案

发生的事情是,您要在其中添加新单元格的 tableview 仍然不知道对 self.fileList 数组所做的更改。不幸的是,UIKit 添加新单元格和检查节数的顺序不受您的控制。然而,为了解决这个问题,UItableview 的插入和删除操作需要包装在 beginsUpdate 和 endsUpdate 方法调用上。

[self.tableView beginUpdates];

// Do all the insertRowAtIndexPath and all the changes to the data source array

[self.tableView endUpdates];

关于ios - 断言失败-[UITableView _endCellAnimationsWithContext],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19357874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com