핵심 데이터 iPhone 애플리케이션을 구축 중이며 일대 다 관계 데이터를 검색하는 데 문제가 있습니다. 설명하는 동안 나와 함께 견뎌주십시오.iPhone 핵심 데이터 관계 오류
데이터 모델 디자이너를 사용하여 "항목"이라는 엔티티를 설정하고 "주석"이라는 많은 엔티티가 포함되어 있습니다. 그런 다음 여러 엔터티를 검색하여 UITableView
에 표시합니다. 행의 사용자 탭은 I가 특정 entiny을 선택하면
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Items" inManagedObjectContext:self.managedObjectContext];
[request setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(Item_to_Areas.Name LIKE %@)",[areaManagedObject valueForKey:@"Name"]];
[request setPredicate:predicate];
[request setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObject:@"Item_to_item_comments"]];
NSLog(@"Results: %@", [mutableItemsFetchResults description]);
mutableItemsFetchResults = [[managedObjectContext executeFetchRequest:request error:nil] mutableCopy];
[request release];
는, init 메소드의 새로운 테이블 뷰 제어기로 전달하고, 밀어 : I합니다 (viewDidLoad
방법) 이와 같은 이들 엔티티 페치 스택에 새로운 뷰 컨트롤러 : 제 1 블록의
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"itemObject: %@", [mutableItemsFetchResults objectAtIndex:indexPath.row]);
InspectionItemCommentsViewController *itemCommentsViewController = [[InspectionItemCommentsViewController alloc]
initWithManagedObjectContext:self.managedObjectContext
itemObject:[mutableItemsFetchResults objectAtIndex:indexPath.row]];
itemCommentsViewController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:itemCommentsViewController animated:YES];
[itemCommentsViewController release];
}
는 NSLog 출력은 "Item_to_item_comments"관계 엔티티 검색되었음을 보여 주지만 초 그것이라고 I는 [요청 setRelationshipKeyPathsForPrefetching 호출하지 않더라도 : [NSArray arrayWithObject : @ "Item_to_item_comments"]].
다음은 첫 번째 NSLog 출력의 일부입니다
Results: (
"<NSManagedObject: 0xb356b70> (entity: Items; id: 0xb34fe60 <x-coredata://E43A90B5-AF0E- 4394-B4A7-5EFE74E181F8/Items/p1> ; data: {\n Clean = nil;\n Description = \"\";\n ItemToInformation = \"<relationship fault: 0x5e1ef00 'ItemToInformation'>\";\n \"Item_to_Areas\" = \"0xb33fd30 <x-coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Areas/p1>\";\n \"Item_to_item_comments\" = \"<relationship fault: 0x5e1d300 'Item_to_item_comments'>\";\n Keys = nil;\n Name = Other;\n \"Tenant_agrees\" = nil;\n Undamaged = nil;\n Working = nil;\n})",
"<NSManagedObject: 0xb35a930> (entity: Items; id: 0xb32acc0 <x-coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Items/p2> ; data: {\n Clean = nil;\n Description = \"\";\n ItemToInformation = \"<relationship fault: 0x790de40 'ItemToInformation'>\";\n \"Item_to_Areas\" = \"0xb33fd30 <x-coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Areas/p1>\";\n \"Item_to_item_comments\" = (\n \"0xb35bcb0 <x-coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Item_Comments/p13>\",\n \"0xb35bcd0 <x-coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Item_Comments/p37>\",\n \"0xb35bca0 <x-coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Item_Comments/p5>\",\n \"0xb35bcc0 <x-coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Item_Comments/p26>\"\n );\n Keys = nil;\n Name = Lights;\n \"Tenant_agrees\" = nil;\n Undamaged = nil;\n Working = nil;\n})",
당신은 항목 개체가 Item_to_item_comments
을 포함하여 가져온 것을 볼 수 있습니다.
itemObject: <NSManagedObject: 0xe20af50> (entity: Items; id: 0xe209fc0 <x- coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Items/p2> ; data: {
Clean = nil;
Description = "";
ItemToInformation = "<relationship fault: 0xe302e40 'ItemToInformation'>";
"Item_to_Areas" = "0xe500b90 <x-coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Areas/p1>";
"Item_to_item_comments" = "<relationship fault: 0xe302e60 'Item_to_item_comments'>";
Keys = nil;
Name = Lights;
"Tenant_agrees" = nil;
Undamaged = nil;
Working = nil;
})
이제 Item_to_item_comments
가 잘못 : 여기에 두 번째 NSLog입니다. 마찬가지로 푸시 된보기 컨트롤러에서 Items 엔터티는 전달되지만 Item_to_item_comments
은 전달되지 않습니다.
나는 분명히 뭔가를 놓치고 있다고 생각하지만, 하루가 지나면이 문제를 해결할 수 없다.
도움을 주시면 감사하겠습니다.
피터
본인은 코어 데이터가 요청 될 때까지 "대다"관계를로드하지 않는다는 것을 알고 있습니다. 문제는 NSLog를 통해 그러한 관계를 요청하고 있지만 여전히 관계 엔티티를 얻을 수 없다는 것입니다. 이 문제에 대한 설명이 적절하기를 바랍니다. 다시 한 번 감사드립니다. – futureshocked
확장을 보려면 내 편집을 참조하십시오. – TechZen
감사합니다. 큰 도움이됩니다. 초보자 실수! – futureshocked