很长时间以来,我一直在获取一个奇怪的bug,其中大部分表格视图变为黑色(只有几个单元格保持为http://cl.ly/LFlS),而在其他视图(连接到相同MOC)中出现一些其他视觉故障:http://cl.ly/LH3c(注意重复部分标题)。我一直认为这是CoreData的一个错误,但直到今天,我都再也没有把它重现到调试器上。下面是我得到异常权利之前它发生了:尝试插入nil对象的NSFetchedResultsController?
CoreData: error: Serious application error. An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. * -[__NSArrayM insertObject:atIndex:]: object cannot be nil with userInfo (null)
它停在[tableView endUpdates]
行我controllerDidChangeContent:
方法。然后,如果我点击继续,该应用程序不会崩溃,但用户交互变得非常缓慢。我看了看那个例外的原因,但找不到任何东西。任何线索?
我的NSFetchedResultsController更改处理看起来很像Apple的样板。我NSFRC的初始化看起来是这样的:
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Artist" inManagedObjectContext:[SWDataManager sharedManager].mainObjectContext];
[request setEntity:entity];
[request setFetchBatchSize:100];
NSSortDescriptor *sortByName = [[NSSortDescriptor alloc] initWithKey:@"sortName" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
[request setSortDescriptors:@[sortByName]];
fetchedResultsController = [[NSFetchedResultsController alloc]
initWithFetchRequest:request
managedObjectContext:mainObjectContext
sectionNameKeyPath:@"firstLetter"
cacheName:nil];
fetchedResultsController.delegate = self;
[self refreshDataSource]; // set fetch request predicate and call performFetch on NSFRC
return fetchedResultsController;
编辑:我可以补充后那一堆对象接到了我MOC从表视图中删除,因此,这绝对发生。
按照要求,我controllerDidChangeContent:
代码:
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
[self.tableView endUpdates];
// this updates the section index and footer cell and other kind of stuff
[self performSelector:@selector(layoutSpecialCells) withObject:nil afterDelay:0.3];
}
您将需要发布你的'-controllerDidChangeContent:'。 – Mundi
@Mundi补充说。就像我说的那样,这没什么特别的...... – samvermette
还添加了我的表格视图后,我得到异常的屏幕截图。 – samvermette