title: Programatically load data finto uitableview using predicate coredata as if table has already had row selected
body: <p>I'm trying to use the excellent code in <a href="http://blog.sallarp.com/iphone-core-data-uitableview-drill-down/" rel="nofollow">http://blog.sallarp.com/iphone-core-data-uitableview-drill-down/</a> to populate fur pop-overs</p>
  
  <pre><code>// 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:&amp;parseError];
  [xmlParse release];
  
  
  // Create a table view controller
  RootViewController *rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStylePlain];
  
  
  
  /*
   ORIGINAL
   */
  rootViewController.managedObjectContext = context;
  rootViewController.entityName = @"County";
  </code></pre>
  
  <p>If I change the entityName to </p>
  
  <pre><code>rootViewController.entityName = @"Province";
  </code></pre>
  
  <p>It loads the second tier of data into the initial view, but want I want is the load only the second tier of data that belongs to a particular first tier row.</p>
  
  <p>So replacing the two lines I've marked as original with</p>
  
  <pre><code>// 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);
  </code></pre>
  
  <p>It would work if I could work out how the replace entityArray with a reference to the initial loading the data.</p>
  
  <p>Hope that makes sense.</p>
  
  <p>Without any code what I'm hoping to achieve is to use the XML to populate four different pop-over uitableviews, each one has already drilled down a level into the data as it loads. I can get straight to all the second data from all the first tier rows, but that's no good, I only want the second tier data from one first tier row per popoverview.</p>
  
  <p>ie emulate this happening</p>
  
  <pre><code>   - (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);
  </code></pre>
  
  <p>I've learnt a lot in the last four hours but not enough and now I'm defeated...</p>