- Why isn't the data from my coredata model loading in the bottom view?
- - (NSFetchedResultsController *)fetchedResultsController {
- // If the fetched results controller already exists, return it
- if (fetchedResultsController_ != nil) {
- return fetchedResultsController_;
- }
- // Otherwise, create it, configure it, and return it
- // Configure the enitity, and attach it to a managed object context
- NSEntityDescription *entity =
- [NSEntityDescription entityForName:@"Top" inManagedObjectContext:self.managedObjectContext];
- // Create the fetch request
- NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
- // Set the fetch request's entity property
- [fetchRequest setEntity:entity];
- /** Set the batch size to a suitable number.
- */
- [fetchRequest setFetchBatchSize:20];
- // Create sort descriptor(s)
- // We will use two here, because we want to group the programs by credential
- NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"topViewPosition" ascending:YES];
- NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey:@"topSecName" ascending:YES];
- NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1, sortDescriptor2, nil];
- // Set the fetch request's sortDescriptors property
- [fetchRequest setSortDescriptors:sortDescriptors];
- // For this root view controller, in this application, we want ALL the Programs
- // Therefore, we will leave out the predicate, which will fetch all the results
- // Clear the cache
- [NSFetchedResultsController deleteCacheWithName:@"Top"];
- // Now, create the fetched results controller
- // Edit the section name key path and cache name if appropriate; nil for section name key path means "no sections"
- NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc]
- initWithFetchRequest:fetchRequest
- managedObjectContext:self.managedObjectContext
- sectionNameKeyPath:@"topSecName" cacheName:@"Top"];
- // Set the fetched results controller's delegate to self; it will call controllerDidChangeContent:
- aFetchedResultsController.delegate = self;
- // Assign this new fetched results controller to the property
- self.fetchedResultsController = aFetchedResultsController;
- // Memory manage
- [aFetchedResultsController release];
- [fetchRequest release];
- [sortDescriptor1 release];
- [sortDescriptor2 release];
- [sortDescriptors release];
- return fetchedResultsController_;
- - (NSFetchedResultsController *)fetchedResultsController {
- // If the fetched results controller already exists, return it
- if (fetchedResultsController_ != nil) {
- return fetchedResultsController_;
- }
- // Otherwise, create it, configure it, and return it
- // Configure the enitity, and attach it to a managed object context
- NSEntityDescription *entity = [NSEntityDescription entityForName:@"Middle"
- inManagedObjectContext:[referringObject_ managedObjectContext]];
- // Create the fetch request
- NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
- // Set the fetch request's entity property
- [fetchRequest setEntity:entity];
- /** Set the batch size to a suitable number.
- */
- [fetchRequest setFetchBatchSize:20];
- // Create sort descriptor(s)
- NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"middleViewPosition" ascending:YES];
- NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey:@"middleSecName" ascending:YES];
- NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1, sortDescriptor2, nil];
- // Set the fetch request's sortDescriptors property
- [fetchRequest setSortDescriptors:sortDescriptors];
- // Predicate configuration - specify the relationship's property name "top"
- // checks whether the value of the key "programs" is the same as the value of the object %@
- NSPredicate *pred = [NSPredicate predicateWithFormat:@"top == %@", self.referringObject];
- [fetchRequest setPredicate:pred];
- // Clear the cache
- [NSFetchedResultsController deleteCacheWithName:@"Middle"];
- // Create the fetched results controller
- // Edit the section name key path and cache name if appropriate; nil for section name key path means "no sections"
- NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc]
- initWithFetchRequest:fetchRequest
- managedObjectContext:[referringObject_ managedObjectContext]
- sectionNameKeyPath:@"middleSecName" cacheName:@"Middle"];
- // Set the fetched results controller's delegate to self; it will call controllerDidChangeContent:
- aFetchedResultsController.delegate = self;
- // Assign this new fetched results controller to the property
- self.fetchedResultsController = aFetchedResultsController;
- // Memory manage
- [aFetchedResultsController release];
- [fetchRequest release];
- [sortDescriptor1 release];
- [sortDescriptor2 release];
- [sortDescriptors release];
- return fetchedResultsController_;
- - (NSFetchedResultsController *)fetchedResultsController {
- // If the fetched results controller already exists, return it
- if (fetchedResultsController_ != nil) {
- return fetchedResultsController_;
- }
- // Otherwise, create it, configure it, and return it
- // Configure the enitity, and attach it to a managed object context
- NSEntityDescription *entity = [NSEntityDescription entityForName:@"Bottom"
- inManagedObjectContext:[referringObject_ managedObjectContext]];
- // Create the fetch request
- NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
- // Set the fetch request's entity property
- [fetchRequest setEntity:entity];
- /** Set the batch size to a suitable number.
- */
- [fetchRequest setFetchBatchSize:20];
- // Create sort descriptor(s)
- NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"bottomViewPosition" ascending:YES];
- NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1, nil];
- // Set the fetch request's sortDescriptors property
- [fetchRequest setSortDescriptors:sortDescriptors];
- // Predicate configuration - specify the relationship's property name "middle"
- // checks whether the value of the key "programs" is the same as the value of the object %@
- NSPredicate *pred = [NSPredicate predicateWithFormat:@"middle == %@", self.referringObject];
- [fetchRequest setPredicate:pred];
- [NSFetchedResultsController deleteCacheWithName:@"Bottom"];
- // Create the fetched results controller
- // Edit the section name key path and cache name if appropriate; nil for section name key path means "no sections"
- NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc]
- initWithFetchRequest:fetchRequest
- managedObjectContext:[referringObject_ managedObjectContext] sectionNameKeyPath:@"bottomSecName" cacheName:@"Bottom"];
- // Set the fetched results controller's delegate to self; it will call controllerDidChangeContent:
- aFetchedResultsController.delegate = self;
- // Assign this new fetched results controller to the property
- self.fetchedResultsController = aFetchedResultsController;
- // Memory manage
- [aFetchedResultsController release];
- [fetchRequest release];
- [sortDescriptor1 release];
- [sortDescriptors release];
- return fetchedResultsController_;
- // This method is called when the user taps/clicks the row to drill down to the next level
- // Get the object for the selected row
- // Note that we don't own the object that we get from the fetched results controller
- // Therefore, we won't release it (memory management) later
- NSManagedObject *selectedObject = [[self fetchedResultsController] objectAtIndexPath:indexPath];
- // Create the next-level view controller
- MiddleList *nextLevelListVC = [[MiddleList alloc] initWithNibName:@"MiddleList" bundle:nil];
- // Set the next-level view controller's display title
- nextLevelListVC.title = [selectedObject valueForKey:@"topName"];
- // Configure the next-level view controller with the selected object
- // We do this here because the next-level view controller is a drill-down table view
- // We may need the selected object to set or follow a Core Data entity relationship
- nextLevelListVC.referringObject = selectedObject;
- // Remember that the managed object context is a property of the referringObject above...
- // Push the next-level view controller onto the navigation stack
- [self.navigationController pushViewController:nextLevelListVC animated:YES];
- // Manage memory
- [nextLevelListVC release];
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- // Get the object for the selected row
- // Note that we don't own the object that we get from the fetched results controller
- // Therefore, we won't release it (memory management) later
- NSManagedObject *selectedObject = [[self fetchedResultsController] objectAtIndexPath:indexPath];
- // Create the next-level view controller
- BottomList *nextLevelListVC = [[BottomList alloc] initWithNibName:@"BottomList" bundle:nil];
- // Set the next-level view controller's display title
- nextLevelListVC.title = [selectedObject valueForKey:@"middleName"];
- // Configure the next-level view controller with the selected object
- // We do this here because the next-level view controller is a drill-down table view
- // We may need the selected object to set or follow a Core Data entity relationship
- nextLevelListVC.referringObject = selectedObject;
- // Remember that the managed object context is a property of the referringObject above...
- // Push the next-level view controller onto the navigation stack
- [self.navigationController pushViewController:nextLevelListVC animated:YES];
- // Manage memory
- [nextLevelListVC release];