술어를 사용하여 코어 데이터에서 오브젝트를 찾습니다. 원하는 객체를 성공적으로 찾을 수 있지만 그 객체의 indexPath를 가져와 해당 객체에 대한 상세 뷰를 푸시 할 수 있어야합니다. 현재 객체를 가져 오는 데 필요한 다음 코드가 있습니다.iPhone : 술어 오브젝트의 인덱스 경로 얻기
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:[NSEntityDescription entityForName:@"Ride" inManagedObjectContext:self.managedObjectContext]];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"title = %@ AND addressFull = %@", view.annotation.title, view.annotation.subtitle];
[fetchRequest setPredicate:predicate];
NSMutableArray *sortDescriptors = [NSMutableArray array];
[sortDescriptors addObject:[[[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES] autorelease]];
[sortDescriptors addObject:[[[NSSortDescriptor alloc] initWithKey:@"addressFull" ascending:YES] autorelease]];
[fetchRequest setSortDescriptors:sortDescriptors];
[fetchRequest setReturnsObjectsAsFaults:NO];
[fetchRequest setPropertiesToFetch:[NSArray arrayWithObjects:@"title", @"addressFull", nil]];
NSError *error = nil;
NSArray *fetchedItems = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
// Sohow what record we returned
NSLog(@"%@",[fetchedItems objectAtIndex:0]);
따라서 개체를 배열로 올바르게 가져올 수 있습니다. 그러나이 객체를 indexPath로 변환하려면 어떻게해야합니까?
예, 맞습니다. UITableView에 표시하고 싶습니다. 클릭 한지도 주석에 대한 세부 정보보기에서 슬라이드하기 만하면됩니다. –
데이터 가져 오기를'NSFetchedResultsController'에 넣고 테이블 뷰 업데이트를하도록 권합니다. 코어 데이터 가져 오기 결과를 테이블 뷰에 연결하는 작업의 약 99 %가 제거됩니다. –
나는 루트 컨트롤러로 init 할 필요가있다. –