在我的代碼中,我想創建帶有List部分的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
我該怎麼辦錯在我的代碼?
完美診斷.. +1。 –
很好的答案,謝謝馬丁! – edzio27