2012-03-26 2 views
3

안녕하세요. 내 앱은 국가별로 그룹화 된 도시 (거리) 목록을 보여줍니다. 나는 새로운 길을 저장할 때 , 그것은 다음과 같습니다CoreData 속성을 고유하게 필터링하고 UITableView에 표시하십시오.

Country -> USA 
City-> New York 
street-> timeSqaure 

것은 내가이만큼의 거리 저장할 때 :

Country -> USA 
City-> New York 
street-> 233 street 330 west 

내의 TableView은 도시 Screenshot

중복을 나는를 필터링 할 수있는 방법 독특한 도시로 중복 된 도시. 이 같은

가져 오기 내 외모는 :

-(void) performFetch 
{ 
    NSFetchRequest *request = [[NSFetchRequest alloc] init]; 
    NSManagedObjectContext *context = [app managedObjectContext]; 
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Country" inManagedObjectContext:context]; 

    [request setEntity:entity]; 


    NSSortDescriptor *sort1 = [[NSSortDescriptor alloc] initWithKey:@"country" ascending:YES]; 
    NSArray *sortArray = [NSArray arrayWithObjects:sort1, nil]; 

    [request setSortDescriptors:sortArray]; 

    NSError *error; 

    self.fetchedResultsController =[[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:context sectionNameKeyPath:@"country" cacheName:nil]; 

    if (![self.fetchedResultsController performFetch:&error]) { 
     NSLog(@"failure: %@", [error localizedDescription]); 
    } 
} 

답변

0

나는 내 문제를 해결했다. 나는 일대 다 관계로 "거리"라는 또 다른 엔티티를 설정했습니다. 그리고 그것은 매력처럼 작동합니다

+0

투표 후보자 아래에있는 '틱'을 클릭하여이 대답을 수락 한 것으로 표시해야합니다. –

관련 문제