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 6122625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:55:15+00:00 2026-05-23T15:55:15+00:00

I´m completely new to core data programming. i just try to find out where

  • 0

I´m completely new to core data programming. i just try to find out where the best place for implementing the core data code would be. i´ve done the apple tutorial Locations and it worked well. now i try to transfer that to my current project what is a bit more complex.

the Locations tutorial shows one RootViewController including a programmatically generated tableView. my project is based on a tabView template. it owns a MainWindow.xib including the TabBarController including three ViewController (MapView, ListView, SettingsView) where each view has it´s own navigationController and xib-file.

The first stumbling block was changing the code that it will run with a xib for the tableView instead of creating it programmatically. I´ve managed that but there is still one error. I can´t connect the managedObjectContext from the appDelegate to the listViewController. I´ve tried the examples and suggestions for that issue from this forum here. but it still doesn´t work.

after looking at the CoreDataBooks sample project i´ve seen that the core data code was implemented in the RootViewController as well. Seems that it would be the wrong way to implement it in the ListViewController. But i don´t have a RootViewController in my project. In the AppDelegate i directly pass the tabBarController as the rootViewController. therefore i don´t know how to reach the listViewController to set the context like it was done in the Locations sample.

As the MapView is the first view i can´t set the context in the appDelegate. And after struggling a long time with the managedObjectContext i wonder if it would be better to invent a RootViewController to be able to place additional code there. the model should be accessible by all three views and it seems that the RootViewController is the right place.

But how do i combine that with a tabBarController which includes three more viewControllers based on xib-files? Could somebody recommend me examples or tutrials including core data based on a tab bar app?

  • 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-23T15:55:16+00:00Added an answer on May 23, 2026 at 3:55 pm

    ok, now i have the correct solution. it took a while to understand but now it works with dependency injection from application delegate into the view controllers (listViewController).

    my problem was that i didn´t know how to reference my view controllers as they are nested into dedicated navControllers and one tabBarController.

    after reading a lot of postings here i understood i have to declare my view controllers in the appDelegate.h and synthesize them in appDelegate.m and after that connect them to the appropirate item in IB. that was done fast & easy after understanding 🙂

    there is no rootViewController needed.

    MyAppDelegate.h:

    #import <UIKit/UIKit.h>
    #import "ListViewController.h"
    
    @interface MyAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
    
        UIWindow *window;
        UITabBarController *tabBarController;
        IBOutlet ListViewController *listViewController;
    }
    
    @property (nonatomic, retain) IBOutlet UIWindow *window;
    @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
    @property (nonatomic, retain) IBOutlet ListViewController *listViewController;
    
    @property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
    @property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
    @property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
    
    - (void)saveContext;
    - (NSURL *)applicationDocumentsDirectory;
    
    @end
    

    MyAppDelegate.m:

    #import "MyAppDelegate.h"
    #import "ListViewController.h"
    
    @implementation MyAppDelegate
    
    @synthesize window=_window;
    
    @synthesize tabBarController=_tabBarController;
    
    @synthesize managedObjectContext=__managedObjectContext;
    
    @synthesize managedObjectModel=__managedObjectModel;
    
    @synthesize persistentStoreCoordinator=__persistentStoreCoordinator;
    
    @synthesize listViewController;
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    
        NSManagedObjectContext *context = [self managedObjectContext];
    
        if (!context) {
            // Handle the error.
        }
        // Pass the managed object context to the view controller.
        listViewController.managedObjectContext = context;
    
        // Override point for customization after application launch.
        // Add the tab bar controller's current view as a subview of the window
        self.window.rootViewController = self.tabBarController;
    
        [self.window makeKeyAndVisible];
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque animated:NO];  
        return YES;
    }
    
    ...
    

    ListViewController.h

    #import <CoreLocation/CoreLocation.h>
    
    
    @interface ListViewController : UITableViewController <CLLocationManagerDelegate> {
    
        UINavigationController *navController;
        NSManagedObjectContext *managedObjectContext;
    }
    
    @property (nonatomic, retain) IBOutlet UINavigationController *navController;
    @property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;
    
    -(NSManagedObjectContext *)managedObjectContext;
    
    @end
    

    ListViewController.m

    #import "MyAppDelegate.h"
    #import "ListViewController.h"
    
    
    @implementation ListViewController
    
    @synthesize navController;
    @synthesize managedObjectContext;
    
    - (void)viewDidLoad {
    
        [super viewDidLoad];
    
        NSLog(@"managedObjectContext: %@",[self managedObjectContext]);
    
        NSError *error = nil;
        if (![managedObjectContext save:&error]) {
            NSLog(@"error: %@",[self managedObjectContext]);
            return;
        }
    
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to the core data programming. I understand that the entities are
I'm completely new to Flex and am just having a play with a sample
I'm completely new to Actionscript and I'm trying to figure out if it's possible
I am completely new to JSF, and just attempting a proof of concept to
I'm completely new to Core Plot and have a working bar graph, but the
I try my best to achieve a kind of UnitOfWork against storing data to
I would like to update my app, but I have completely changed the data
I'm not sure that I completely understand how Core Data works on iOS. I
Completely new to asp.net mvc... completely new to web apps so bear with me...
I am completely new to ruby and I inherited a ruby system for a

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.