Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Unsubscribed User
1,097 PointsNavigating through TabBar > Navigation > TableView to pass managedObjectContext
Hey there,
So I'm following the "Core Data" Tutorial for IOS development and i'm a little stuck :s (Link)
In the tutorial, he tries to pass his managedObjectContext to his ListViewController in the AppDelegate class. (12:20)
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
ListViewController *controller = (ListViewController *)navigationController.topViewController;
controller.managedObjectContext = self.controller.managedObjectContext;
controller.managedObjectModel = self.controller.managedObjectModel;
But my application is not structured like his, it's more like this : TabBarController > NavigationController > TableViewController. And i don't know how to pass my managedObjectContext to the TableViewController, i don't know how to navigation through these tree Views.
I've tried to access my Tables View Controller by the storyboard :
UIStoryboard *SB = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
EventTableViewController* GL = [SB instantiateViewControllerWithIdentifier:@"Event"];
GL.managedObjectContext = [self managedObjectContext];
GL.managedObjectModel = [self managedObjectModel];
It seems to find the EventTableViewController but the managedObjectContext is not set because each time i try to pass it with a segue i get this error :
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'Event''
Can you help me please ? Feel free to ask if it's not clear enough.
Thanks, Greg
1 Answer
Unsubscribed User
1,097 PointsI've solved my problem by navigating through views with childViewControllers propriety :
ProjectUITabBarController *PUITBC = (ProjectUITabBarController *)self.window.rootViewController;
UINavigationController *UINC = (UINavigationController *)PUITBC.childViewControllers[0];
EventTableViewController *GVC = (EventTableViewController *)UINC.childViewControllers[0];
GVC.managedObjectContext = [self managedObjectContext];
GVC.managedObjectModel = [self managedObjectModel];