gpt4 book ai didi

iphone - NSFetchedResultsController 错误 : 'NSInternalInconsistencyException' , 原因: 'no object at index 1 in section at index 0'

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:52:17 24 4
gpt4 key购买 nike

我有一个使用 tableview 和 NSFetchedResultsController 的应用程序。我收到错误:

Serious application error.  Exception was caught during Core Data change processing.  This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification.   Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'no object at index 1 in section at index 0'

...来自下面的代码。 selectedevents 是一个数组,其计数等于 fetched results controller 中对象的计数。

NSManagedObjectContext *context = [fetchedResultsController managedObjectContext];
NSMutableArray *array=[[NSMutableArray alloc] init];
for (int i=0; i<[self.selectedEvents count]; i++) {
CustomDictionary *dic=[selectedEvents objectAtIndex:i];
if (dic.isSelected) {
Event *evt=[fetchedResultsController objectAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
[array addObject:evt];
}
}
for (Event *evt in array) {
[context deleteObject:evt];
}
NSError *error;
if (![context save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}

最佳答案

in the code below "selectedevents" is an array whose count is equal to that of objects in fetched results controller.

但是

error says that 'no object at index 1 in section at index 0' your fetched result controller may have multiple sections.

另外,代码应该是:

NSManagedObject *evt=[fetchedResultsController objectAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];

...不是:

Event *evt=[fetchedResultsController objectAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];

关于iphone - NSFetchedResultsController 错误 : 'NSInternalInconsistencyException' , 原因: 'no object at index 1 in section at index 0',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6545300/

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