我正在尝试使用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";
它将第二层数据加载到初始视图中,但我想要的是仅加载属于特定第一层行的第二层数据。
因此,将我标记为原始的两行替换为
// 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 填充四个不同的弹出式 uitableviews,每个都在加载数据时已经向下钻取了一个级别。我可以直接从所有第一层行中获取所有第二层数据,但这并不好,我只想要每个 popoverview 中一个第一层行的第二层数据。
即模仿这种情况
- (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);
在过去的四个小时里,我学到了很多东西,但还不够,现在我被打败了……