在过去的几个小时里,我一直在撕掉我的头发,试图找出为什么这不起作用。我在Core Data中有一对多的关系,并试图正确地将值传递给细节segue。一对多关系核心数据:抓取prepareForSegue:
下面是数据模型(该属性是二进制数据类型):
如果我取的configureCell数据:方法,它给我的预期值:
- (void)configureCell:(UITableViewCell *)cell atIndexPath(NSIndexPath *)indexPath
{
TBAppDelegate *delegate = (TBAppDelegate *)[[UIApplication sharedApplication] delegate];
managedObjectContext = [delegate managedObjectContext];
self.everything = [fetchedResultsController.fetchedObjects objectAtIndex:indexPath.section];
NSArray *arg = [NSKeyedUnarchiver unarchiveObjectWithData:self.everything.urls.urls];
NSLog (@"%@, [arg valueForKey:@"source"]); // this prints out a list of stored urls containing locations of jpeg images
}
我NSFetchedResultsController:
- (NSFetchedResultsController *)fetchedResultsController
{
TBAppDelegate *delegate = (TBAppDelegate *)[[UIApplication sharedApplication] delegate];
self.managedObjectContext = delegate.managedObjectContext;
NSFetchRequest *fetchRequest = nil;
fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = nil;
entity = [NSEntityDescription entityForName:@"Everything" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
[fetchRequest setFetchBatchSize:INFINITY];
NSSortDescriptor *albumDescriptor = nil;
albumDescriptor = [[NSSortDescriptor alloc] initWithKey:@"album_names" ascending:NO];
NSSortDescriptor *urlDescriptor = nil;
urlDescriptor = [[NSSortDescriptor alloc] initWithKey:@"urls.urls" ascending:NO];
NSArray *sortDescriptors = nil;
sortDescriptors = [[NSArray alloc] initWithObjects:albumDescriptor, urlDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
NSFetchedResultsController *frc = nil;
frc = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];
[frc setDelegate:self];
[self setFetchedResultsController:frc];
return frc;
}
这是我的prepareForSegue:方法。这部分不起作用。当我尝试设置详细视图控制器的部分数时,它会崩溃,并出现无法识别的选择器错误。详细信息视图控制器的
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSIndexPath *indexPath;
indexPath = [self.tableView indexPathForSelectedRow];
TBAppDelegate *delegate = (TBAppDelegate *)[[UIApplication sharedApplication] delegate];
managedObjectContext = [delegate managedObjectContext];
self.everything = [fetchedResultsController.fetchedObjects objectAtIndex:indexPath.section];
NSArray *data = [NSKeyedUnarchiver unarchiveObjectWithData:self.everything.album_names];
NSArray *urls = [NSKeyedUnarchiver unarchiveObjectWithData:self.everything.urls.urls];
TBEverythingDetailViewController *details = segue.destinationViewController;
details.everything = [[data objectAtIndex:indexPath.section]valueForKey:@"name"];
self.urls.urls = [fetchedResultsController.fetchedObjects objectAtIndex:indexPath.section];
details.everythingGroup = [urls objectAtIndex:indexPath.section];
}
部分:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// This is where the actual crash happens. It complains about [_NSDictionaryM urls:] unrecognized selector sent to instance
NSArray *count = [NSKeyedUnarchiver unarchiveObjectWithData:self.everythingGroup.urls.urls];
return [count count];
}
我觉得我在这里缺少一些明显的阶梯,为什么它不工作。我可以得到任何帮助吗?
你真的从-fetchedResultsController返回一个NSFetchedResultsController吗? – Joride