我是核心數據的新手,我需要以下問題的幫助:關係錯誤(核心數據)
我有兩個實體:Talk和Speaker。他們有很多關係。
講座 - 目的地:喇叭,逆:談 音箱 - 目的地:談話,反:揚聲器
場「一對多關係」是在兩個實體進行檢查。
我有一個表視圖控制器列出所有可用的會談。這就是爲什麼我做的:
- (NSFetchedResultsController *)fetchedResultsController
{
if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Talk" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
NSSortDescriptor *sort = [[NSSortDescriptor alloc]
initWithKey:@"date" ascending:NO];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];
[fetchRequest setFetchBatchSize:20];
NSFetchedResultsController *theFetchedResultsController =
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil
cacheName:@"Root"];
self.fetchedResultsController = theFetchedResultsController;
_fetchedResultsController.delegate = self;
return _fetchedResultsController;
}
當我點擊一個細胞,我想在另一視圖控制器,顯示所選擇的談話只是細節。
這是我在做什麼:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TalksDetailsViewController *talksDetails = [[TalksDetailsViewController alloc] initWithTalksInfo:[_fetchedResultsController objectAtIndexPath:indexPath]];
[self.navigationController pushViewController:talksDetails animated:YES];
}
的問題是:我不能看到TalksDetailsViewController揚聲器。這是發送到TalksDetailsViewController的信息:
Info: <Talk: 0x6e66920> (entity: Talk; id: 0x6e66880 <x-coredata://4063FE84-E6DB-4588-8133-9A55B512D6C8/Talk/p2> ; data: {
date = "2012-08-31 03:00:00 +0000";
id = 7;
speaker = "<relationship fault: 0x6e994e0 'speaker'>";
"start_time" = "17:14:55";
})
我試過的東西如下面的代碼,但它並沒有奏效:
for (Speaker *speakerInfo in self.talkInfo.speaker) {
NSLog(@"speaker info: %@", speakerInfo);
}
它永遠不會進入的。
如果我嘗試登錄self.talkInfo.speaker我得到的東西,如:
Relationship 'speaker' fault on managed object (0x7a76c30) <Talk: 0x7a76c30> (entity: Talk; id: 0x7a76b90 <x-coredata://4063FE84-E6DB-4588-8133-9A55B512D6C8/Talk/p2> ; data: {
date = "2012-08-31 03:00:00 +0000";
id = 7;
speaker = "<relationship fault: 0x6bc5990 'speaker'>";
"start_time" = "17:14:55";
})
我看到了一些類似的問題,但未能解決我的問題。
任何提示?
關係錯誤並不意味着錯誤,你有沒有嘗試從揚聲器記錄屬性?看到這個答案:http:// stackoverflow。com/a/8876336/879119 – mkral
試過了,但沒有奏效。根據您指出的答案無法解決我的問題。但是,謝謝。 – hdoria
你能記錄self.talkInfo嗎?所以我可以看到它的結構如何: – mkral