1
我的表用于列出核心数据中的行。一切工作正常,我已经使用两种类型的数据加载在同一个表视图。数据类型因范围按钮更改而改变。两个范围按钮之一显示已完成的任务,而其他显示未完成的任务我可以在桌面上搜索,更新。虽然只完成DATAS的列表是可编辑的,可以被删除,有时它工作正常,有时它给误差等,应用程序在删除行时崩溃
Serious application error. An exception was caught from the delegate of
NSFetchedResultsController during a call to -controllerDidChangeContent:. *** -
[NSMutableArray insertObject:atIndex:]: index 4 beyond bounds for empty array with
userInfo (null)
的获取结果控制器初始化为,
- (NSFetchedResultsController *)fetchedResultsControllerWithPredicate:(NSPredicate *)predicate{
if (self.fetchedResultsControl != nil) {
NSLog(@"Here I am outside");
return self.fetchedResultsControl;
}
的代码加载小区的tableview是:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
CustomCell *cell =(CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects=[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:nil options:nil];
for (id currentObject in topLevelObjects) {
if([currentObject isKindOfClass:[UITableViewCell class]]){
cell=(CustomCell *)currentObject;
break;
}
}
}
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
甲nd NSFetchedResultsControllerDelegate调用的更新方法为;
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
[self.listingTable beginUpdates];
NSLog(@"Changed content");
}
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id < NSFetchedResultsSectionInfo>)sectionInfo
atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {
switch(type) {
case NSFetchedResultsChangeInsert:
[self.listingTable insertSections:[NSIndexSet indexSetWithIndex:sectionIndex]
withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
[self.listingTable deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex]
withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath {
NSLog(@"Changed content switch case");
UITableView *tableView = self.listingTable;
switch(type) {
case NSFetchedResultsChangeInsert:
[self.listingTable insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
withRowAnimation:UITableViewRowAnimationTop];
break;
case NSFetchedResultsChangeDelete:
[self.listingTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeUpdate:
[self configureCell:(CustomCell *)[tableView cellForRowAtIndexPath:indexPath]
atIndexPath:indexPath];
break;
case NSFetchedResultsChangeMove:
[self.listingTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
[self.listingTable insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
NSLog(@"Changed Content");
[self.listingTable endUpdates];
}
我在numberOfRowsInSection中实现了日志,但更新是正确的,因此删除前的行数大于1,然后删除。 – Sandeep 2011-05-12 08:15:10
但也尝试打印托管对象的未见行,所以日志给出的消息:(实体:Memos; id:0x7150c10 ;数据:)。但是一旦表格滚动,删除就成为可能。这是使用两个单独的列表与相同的fetchedresultscontroller和相同的表视图的错误。 –
Sandeep
2011-05-12 08:20:58
我不能肯定你的设计是造成问题,但我认为它可能。 – TechZen 2011-05-12 22:28:51