hi, i am currently working on a test project which has a tab bar, a drill down table list of Districts --> Schools --> school details.
Data store is using core data/.mysqlite
*Districts' view is a plain table list which list out districts
**Schools' view is a table view with custom cell which display name,address and picture of schools in the selected district
***Detail view is a sectioned table with more details of the selected school.
I have managed to get the district table view setup and display correctly but I am stuck on pushing the 2nd view which is the School view. How could I pass data to the 2nd view or switch the Fetch Result entity? I have tried with different method but it is having error, probably it's because I am using the wrong method or missing something at didSelectRow
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'School'
I couldn't find out what the problem is. Would be great if anyone could give me some hints on that.
DistrictListTableViewController -- FRO, MOC fetching "District"
NSEntityDescription *entity = [NSEntityDescription entityForName:@"District" inManagedObjectContext:managedObjectContext]; [fetchRequest setEntity:entity];
@class District;
@interface DistrictListTableViewController : UITableViewController { @private NSFetchedResultsController *fetchedResultsController; NSManagedObjectContext *managedObjectContext; }
@property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController;
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;
SchoolListTableViewController -- FRO, MOC fetching "School"
NSEntityDescription *entity = [NSEntityDescription entityForName:@"School" inManagedObjectContext:managedObjectContext]; [fetchRequest setEntity:entity];
@class School;
@interface DistrictListTableViewController : UITableViewController { @private NSFetchedResultsController *fetchedResultsController; NSManagedObjectContext *managedObjectContext; }
@property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController;
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;
Both DistrictListTableViewController & SchoolListTableViewController .m files are pretty much the same except School View loads the SchoolTableViewCell file, I don't know if this is the right method.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
SchoolListTableViewController *schoolViewController = [[SchoolListTableViewController alloc] initWithStyle:UITableViewStylePlain];
[self.navigationController pushViewController:mallViewController animated:YES];
[schoolViewController release];
}
I am pretty new to this, so please tell me where did I do wrong and what is the right method of passing the entity and data to the 2nd view and how.
Thank you very much.
thanks and this is my fetchedcontroller part
> - (NSFetchedResultsController *)fetchedResultsController {
if (fetchedResultsController != nil) {
return fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"District" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
NSSortDescriptor *locateDescriptor = [[NSSortDescriptor alloc] initWithKey:@"territory" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:locateDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"territory" cacheName:@"Root"];
self.fetchedResultsController = aFetchedResultsController;
fetchedResultsController.delegate = self;
[aFetchedResultsController release];
[fetchRequest release];
[locateDescriptor release];
[sortDescriptors release];
return fetchedResultsController;
}
so, in the School controller, i would just switch "District" with "School" and sort description with the name of the school.