0

I'm trying to attach my MOC to a UITableViewController that has been created using Xcode 5 Storyboards. The nesting is like this: UITabBarController -> UINavigationController -> UITableView. I'm instantiating the MOC in the AppDelegate and I want to pass it to the UITableView. Any suggestions?

Thanks!

Thanks, the CoreDataBooks example does something like this: But their Storyboard is directly from UINavigationController -> UITableView.

UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
RootViewController *rootViewController = (RootViewController *)[[navigationController viewControllers] objectAtIndex:0];
rootViewController.managedObjectContext = self.managedObjectContext;

I guess I can use method #1 below but what's the proper way to identify the UITabBarController from AppDelegate? I guess I need to instantiate that as its own class and import that into the delegate too?

Marco
  • 6,692
  • 2
  • 27
  • 38
4m1r
  • 12,234
  • 9
  • 46
  • 58

1 Answers1

0

There are many ways to pass MOC from appDelegate to yourViewController. You can see a detailed discussion on this topic in my Question here

I would like to list down the possible ways:

  1. Instantiate & assign MOC to your VC from appDelegate.
  2. Call appDelegate from your VC by using this code:

    myAppDelegate * del= [[UIApplication sharedApplication]delegate];

& get the context like this:

myContext = del.context;

You can go through above question for a detailed argument.. :)

Community
  • 1
  • 1
Prince Agrawal
  • 3,619
  • 3
  • 26
  • 41