好的我正试图抓住一个NSMutable集。是的我之前有一篇文章,但这有点不同。我有一个玩家实体和一个团队实体。它被设置为一对多的关系...在不同的视图控制器上,我向球队添加了球员。现在我试图让那些队员出现在桌面视图上......我正在获取如下信息。
- (NSFetchedResultsController *)fetchedResultsController {
if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}
NSString *entityName = @"Team";
NSLog(@"Setting up a Fetched Results Controller for the Entity named %@", entityName);
// 2 - Request that Entity
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:entityName];
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
_managedObjectContext = delegate.managedObjectContext;
// 4 - Sort it
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"players"
ascending:NO
selector:@selector(localizedCaseInsensitiveCompare:)]];
// 5 - Fetch it
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:self.managedObjectContext
sectionNameKeyPath:nil
cacheName:nil];
_fetchedResultsController.delegate = self;
return _fetchedResultsController;
}
然后在索引路径上的行的单元格中,我将Player对象设置为获取的结果,如下所示
Player *p = [_fetchedResultsController objectAtIndexPath:indexPath];
然后,我正在设置单元格的标题。
cell.textLabel = p.firstName;
我收到错误 理由:'to-many key不允许她
我想知道我做错了什么???
答案 0 :(得分:0)
想出来!我正在对一对多的关系进行排序,这在Core Data中是NO NO。我切换到玩家对象的排序并添加了一个谓词来找到我需要的合适玩家。