2012-01-24 7 views
0

가져 오기 :코어 데이터가 나는이처럼 보이는 데이터 모델이 요청

enter image description here

나는 사용자가 고객을 선택하는있는 tableview에 고객의 목록이 표시를, 그 다음 객실의 목록을 보여줍니다 그 고객 -이 모든 것이 현재 잘 작동합니다.

내가보기에 문제는 방에 대한 세부 정보보기를 시도 할 때입니다. 사용자가 방을 선택하면 해당 방의 모든 값이 표시된보기가 표시됩니다. (잘해야한다). 나는 어느 정도는 작동하지만, 만약 내가 같은 두 개의 방이있다 - 즉, "침실 1", 두 명의 다른 고객을위한 다음 그것은 정확한 방 데이터를 보여주지 않습니다.

, 상세 뷰는 내가 뭘 어떻게 할
AppDelegate_Shared *appDelegate = [[UIApplication sharedApplication] delegate]; 

    NSManagedObjectContext *context = [appDelegate managedObjectContext]; 

    NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"Rooms" inManagedObjectContext:context]; 

    NSFetchRequest *request = [[NSFetchRequest alloc] init]; 

    [request setEntity:entityDesc]; 

    NSPredicate *pred = [NSPredicate predicateWithFormat:@"(Room = %@)", titleStr]; 

    [request setPredicate:pred]; 

    NSManagedObject *matches = nil; 
    NSError *error; 

    NSArray *objects = [context executeFetchRequest:request error:&error]; 

    if ([objects count] == 0) 
    { 
     NSLog(@"No matches"); 
    } else 
    { 
     matches = [objects objectAtIndex:0]; 
     NSLog(@"matches found"); 
     aLbl.text = [matches valueForKey:@"DimA"]; 
    } 
    [request release]; 
    [NSFetchedResultsController deleteCacheWithName:nil]; 
    [self.fetchedResultsController.fetchRequest setPredicate:pred]; 

이 이미 선택되어 어떤 고객을 기반으로 세부 사항을 보여줍니다 여기

내가 사용하고있는 코드입니다.

어떤 도움이 많이 감사합니다 ...

감사

답변

1
또한 당신이 찾고있는 고객을 포함하도록 조건을 변경

.

이것은 (SQL을 사용했다고 가정 할 때) SQL이라고 가정하면, 조건자는 WHERE 절입니다. Room이 고유하지 않으면 동일한 이름의 모든 방이 반환됩니다.

원하는 것은 ROOM == roomName 및 customer == customerId 인 객실입니다.

+0

[NSPredicate predicateWithFormat : @ "(Room == % @) AND (CustomerRelationship == % @)", titleStr, customerManagedObject] – zrxq

+0

감사합니다. 활을 가져 가라 :-) –

관련 문제