Passing managedObjectContext via presentViewController

I am trying the "pass the baton" method for passing the managedObjectContext (MOC) thru multiple views. I have it successfully passed to the rootViewController. From there I move to a tabBarController via presentViewController. I can't seem to find a way to pass the MOC when the tabBarController is pushed.

AppDelegate.m

UIViewController *navigationController = (UIViewController *)self.window.rootViewController;
MyViewController *controller = (MyViewController *) navigationController;
controller.managedObjectContext = managedObjectStore.mainQueueManagedObjectContext;

The main view controller is basically a start up screen that will kick you into a login screen or if you are already logged in, to the tabBarController. Below is where I transition to the tabBarController from within the viewDidAppear method.

MyViewController.m

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
UIViewController *mainTabVC = [storyboard instantiateViewControllerWithIdentifier:@"mainTabVC"];
[mainTabVC setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:mainTabVC animated:NO completion:nil];

The tabBarController in the storyboard has the identifier "mainTabVC".

I've tried lines like

MyTabBarController.managedObjectContext = self.managedObjectContext;

but I get the error Property 'MOC' not found on object of type MyTabBarController even though I do have the property declared in MyTabBarController.h

Could someone show me a line of code that I can throw in this segue to push the MOC to the tab bar controller.

BTW- I'm utilizing RestKit in this app if that changes the way I should be handling this please let me know.

*****Solution********

To make things clear for any other new guys with the same question. I went from this:

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
    UIViewController *mainTabVC = [storyboard instantiateViewControllerWithIdentifier:@"mainTabVC"];
    [mainTabVC setModalPresentationStyle:UIModalPresentationFullScreen];
    [self presentViewController:mainTabVC animated:NO completion:nil];

To this:

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
    MyTabBarViewController *mainTabVC = [storyboard instantiateViewControllerWithIdentifier:@"mainTabVC"];
     mainTabVC.managedObjectContext = self.managedObjectContext;
    [mainTabVC setModalPresentationStyle:UIModalPresentationFullScreen];
    [self presentViewController:mainTabVC animated:NO completion:nil];

Notice the assignment in the third line and using MyTabBarViewController instead of UIViewController in the second line. BIG thanks again to rdelmar!

Answers


Your code is somewhat confusing. Is MyTabBarController the class? It looks like mainTabVC is your instance. You should use that rather than the class, and you should change the type when you instantiate mainTabVC to MyTabBarController, instead of UITabBarController. You also don't need to get the storyboard the way you do, you can just use self.storyboard.

    MyTabBarController *mainTabVC = [self.storyboard instantiateViewControllerWithIdentifier:@"mainTabVC"];
    mainTabVC.managedObjectContext = self.managedObjectContext;
    [mainTabVC setModalPresentationStyle:UIModalPresentationFullScreen];
    [self presentViewController:mainTabVC animated:NO completion:nil];

Need Your Help

Implementing a secondary authentication scheme in

database ldap oracle10g oracle-apex

I have an apex application that authenticates using LDAP which would also check to see if a certain value in the database is true or false. I can't see how I can combine authentications.

How to make an event empty again?

.net winforms events methods delphi-prism

If you have an Winform MouseDown event set to a method, how do you empty or reset the event. so that it has no methods to call when it fires.

Does putExtras() unarchive and then archive the extras again?

java android extras

I'm working on an android application project, and I have a scenario where I send data between activities in the following order: