在我的代码中,我想创建带有列表部分的 tableView。我使用这样的方案:
我使用我以这种方式定义的 NSFetchResultController :
- (NSFetchedResultsController *)fetchedResultsController {
if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Item" inManagedObjectContext:coreDataController.masterManagedObjectContext];
[fetchRequest setEntity:entity];
NSSortDescriptor *sort = [[NSSortDescriptor alloc]
initWithKey:@"addedAt" ascending:YES];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];
[fetchRequest setFetchBatchSize:20];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"itemIsChecked = 1"];
[fetchRequest setPredicate:predicate];
[fetchRequest setResultType:NSDictionaryResultType];
NSFetchedResultsController *theFetchedResultsController =
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:coreDataController.masterManagedObjectContext sectionNameKeyPath:@"toList.listName"
cacheName:nil];
self.fetchedResultsController = theFetchedResultsController;
_fetchedResultsController.delegate = self;
return _fetchedResultsController;
}
现在在 cellForRowAtIndexPath: 我想从我的 fetchResultController 中获取数据,所以我这样做:
Item *item = [self.fetchedResultsController objectAtIndexPath:indexPath];
然后如果我想访问项目的字段之一(例如 itemText),它会崩溃:
NSLog(@"item itemtext = %@", item.itemText);
有错误:
-[NSKnownKeysDictionary1 itemText]: unrecognized selector sent to instance 0x1215fd90
我的代码做错了什么?