http://blog.sallarp.com/iphone-core-data-uitableview-drill-down/の優れたコードを使用して、毛皮のポップオーバーを作成しようとしています。
// Override point for customization after app launch
NSManagedObjectContext *context = [self managedObjectContext];
// We're not using undo. By setting it to nil we reduce the memory footprint of the app
[context setUndoManager:nil];
if (!context) {
NSLog(@"Error initializing object model context");
exit(-1);
}
// Get the url of the local xml document
NSURL *xmlURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Data" ofType:@"xml"]];
NSError *parseError = nil;
// Parse the xml and store the results in our object model
LocationsParser *xmlParse = [[LocationsParser alloc] initWithContext:context];
[xmlParse parseXMLFileAtURL:xmlURL parseError:&parseError];
[xmlParse release];
// Create a table view controller
RootViewController *rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStylePlain];
/*
ORIGINAL
*/
rootViewController.managedObjectContext = context;
rootViewController.entityName = @"County";
entityNameをに変更した場合
rootViewController.entityName = @"Province";
データの第2層を初期ビューにロードしますが、特定の第1層の行に属するデータの第2層のみをロードする必要があります。
したがって、オリジナルとしてマークした2行を次のように置き換えます
// Get the object the user selected from the array
NSManagedObject *selectedObject = [entityArray objectAtIndex:0];
// Pass the managed object context
rootViewController.managedObjectContext = self.managedObjectContext;
rootViewController.entityName = @"Province";
// Create a query predicate to find all child objects of the selected object.
NSPredicate *predicate = nil;
predicate = [NSPredicate predicateWithFormat:@"(ProvinceToCounty == %@)", selectedObject];
NSLog(@"selectedObject %@",selectedObject);
entityArrayをデータの初期ロードへの参照で置き換える方法を理解できればうまくいくでしょう。
それが理にかなっていることを願っています。
私が達成したいと思っているコードがない場合は、XMLを使用して4つの異なるポップオーバーuitableviewにデータを入力します。各ビューは、データの読み込み時にすでにレベルをドリルダウンしています。すべての第1層の行からすべての第2層のデータを直接取得できますが、それは良くありません。ポップオーバービューごとに1つの第1層の行からの第2層のデータのみが必要です。
つまり、これが起こっていることをエミュレートします
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Force the data from index 1 of first tier
NSManagedObject *selectedObject = [entityArray objectAtIndex:1];
rootViewController.managedObjectContext = self.managedObjectContext;
NSPredicate *predicate = nil;
rootViewController.entityName = @"Province";
predicate = [NSPredicate predicateWithFormat:@"(ProvinceToCounty == %@)", selectedObject];
NSLog(@"selectedObject %d %@",indexPath.row, selectedObject);
私は過去4時間で多くのことを学びましたが、十分ではなく、今は敗北しています...