Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6181015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:56:47+00:00 2026-05-24T00:56:47+00:00

My RootViewController contains a simple table view. Upon selecting one of the entries in

  • 0

My RootViewController contains a simple table view. Upon selecting one of the entries in the table a DetailViewController is shown with more details on the selected entry. The data of the relevant data object is loaded and persisted via CoreData. How do I pass on the FetchedResultsController and the ManagedObjectContext to the DetailViewController in the didSelectRowAtIndexPath: method?
Do I need to define properties for both in the DetailViewController.h? Can you provide me with a code sample?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:56:48+00:00Added an answer on May 24, 2026 at 12:56 am

    Firstly, each fetched results controller (FRC) instance is configured specific to each tableview so you don’t pass FRC from tableview controller to tableview controller. Instead, each tableview controller instantiates and configures a new FRC specifically for its tableview.

    In a Master-Detail design where the tableview is the master view, you don’t pass the FRC to the detail view but instead just the single managed object that is represented by the selected tableview row.

    Apple recommends that the managed object context (MOC) be passed by “dependency injection”. This is very simple. In the most common design, you initialize the MOC in the app delegate, then provide each of your view controllers with a managedObjectContext property. Then when you load/push a view controller, you just set it’s managedObjectContext property to the MOC.

    For example, in a Master-Detail design, you usually have a navigation controller (NAV). To see how this works, create a test app using the navigation based app template in Xcode. Mark it to use Core Data. You will that both the app delegate and the RootViewController have a managedObjectContext property.

    Now in the app delegate’s applicationDidFinishLaunching:... method add the code to make it look like:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
      // Override point for customization after application launch.
      // Add the navigation controller's view to the window and display.
      RootViewController *topVC=(RootViewController *) self.navigationController.topViewController;
      topVC.managedObjectContext=self.managedObjectContext;
      self.window.rootViewController = self.navigationController;
      [self.window makeKeyAndVisible];
        return YES;
    }
    

    … then in the RootViewController.m add:

    - (void)viewDidAppear:(BOOL)animated
    {
      NSLog(@"self.managedObjectContext = %@",self.managedObjectContext);
      [super viewDidAppear:animated];
    }
    

    When you run the test app the RootViewController object will log it’s managedObjectContext property something like:

    2011-07-19 09:24:05.193 CDNavTemplate[3203:207] self.managedObjectContext = <NSManagedObjectContext: 0x4d318a0>
    

    … proving that the RootViewController object has the managed object context from the app delegate.

    Now, you just repeat the process for every view controller you push onto the navigation controllers stack progressively handing the same managed object context object down the view hierarchy. You can pass any other type of object the exact same way.

    Apple recommends dependency injection because it makes the code more modular and makes it easy to use multiple managed object context within a single app. You just pass each particular view controller the specific context it needs at any particular time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view controller that contains a table view, the items in the
I have a view controller which contains a table view, and which is wrapped
I have a UITabBar with 2 views. One view contains a UITable. When I
I have two view controllers name RootViewController and SecondViewController. In the FirstViewController I have
- (void)applicationDidFinishLaunching:(UIApplication *)application { // Create the navigation and view controllers RootViewController *rootViewController =
I'm using a StoryBoard which contains various ViewControllers and a TableViewController, one in particular
I have a RootViewController and a DetailViewController where I am trying to pass a
I was to pass a NSString from RootViewController(UITableViewController) to DetailViewController . t RootViewController.m -
In the main UITableView for a RootViewController. How can I add a View over
So, I push a view controller from RootViewController like: [self.navigationController pushViewController:anotherViewController animated:YES] ; BUT,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.