I am playing about with Core Data and very new to it. This chunk of code seems pretty important:
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
MasterViewController *controller = (MasterViewController *)navigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
It sets the managedObjectContext to the desired view right? (This time being MasterViewController
Now I have played with it but can’t seem to get it working. What if I want to launch the MasterViewController from somewhere else in the app, not directly from/as the root view?
Edit
My views as seen in InterFace Builder:
UINavigationController >Relationship> UIViewController >Push Segue> UITableViewController
So in Interface builder, the UINavigationBar is the blank, first controller and then UIViewController is connected to that and is the first view the user will see in the app. Then I want to get from there to my UITableViewController where I have my CoreData usage.
You have two solutions :
You have to passed your
NSManagedObjectContextthrought all your app between all your UIViewControlleror
Get your
NSManagedObjectContextfrom anywhere like that :