iphone tab bar controller and core data
Asked Answered
C

4

13

Ok bit of a newbie type question.

I want to use Core Data, together with Tab and Navigation controllers.

In XCode if I create a Navigation Based Application I get the option to choose Core Data. Whereas If I create a Tab Bar Application I don't get the choice.

I understand that Tab Bars display view controllers so it kinda makes sense. However given that by default it sticks the basic Core Data code in the Application delegate I don't see why this isn't offered.

At the moment I'm creating the two projects and cutting and pasting between them.

Does this omission in XCode seem weird to you? Is it some sort of oversight?

Thanks, Matt

Coterie answered 2/9, 2009 at 4:13 Comment(0)
G
6

The templates are designed to be more 'pure', any combination of the templates is left as an exercise for the developer.

They could do a CoreData + Tab and Nav Controller template, but to be fair they'd then have to do every other combination that might be 'reasonable'.

Combining them yourself isn't that hard, and there's sample apps in the dev centre that show some of the combinations within a working application.

Gazelle answered 2/9, 2009 at 4:26 Comment(0)
L
12

I've faced the same problem and ended up creating a tabBar app and adding the core data stuff later.

To do so, I've:

  1. added the coredata framework to my project
  2. added #import < CoreData/CoreData.h > to myproject_Prefix.pch
  3. added declarations to delegate header and getter implementations just as created by the templates that support core data
  4. create model file - add file to resources group (or wherever you want to put your model stuff) and create a data model file.

This should get you to the same point you would be at with the core data supporting templates.

For your specific case (core data with tabbar), Apple have a good sample app:

http://developer.apple.com/iphone/library/samplecode/iPhoneCoreDataRecipes/index.html

This shows how they pass the context through to the relevant view controller defined in the xib file which was the thing that held me up for a while.

Hope this helps.

Cheers, Peter

Leija answered 14/12, 2009 at 5:36 Comment(0)
C
7

You can add it yourself it's very simple to do:

To modify Tab Bar template settings you have to open the following file

For XCode 4.2:

/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/Application/Tabbed Application.xctemplate/TemplateInfo.plist

To add core data option you have to add the property "com.apple.dt.unit.coreDataCocoaTouchApplication" to the Ancestors key:

after adding the property it should look like this:

<key>Ancestors</key>

<array>
<string>com.apple.dt.unit.storyboardApplication</string>
<string>com.apple.dt.unit.coreDataCocoaTouchApplication</string>
</array>

For Previous XCode Versions

/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/Application/Tab Bar Application.xctemplate/TemplateInfo.plist

To add core data option you have to add the property "com.apple.dt.unit.coreDataCocoaTouchApplication" to the Ancestors key:

after adding the property it should look like this:

<key>Ancestors</key>

<array>
<string>com.apple.dt.unit.cocoaTouchFamiliedApplication</string>
<string>com.apple.dt.unit.coreDataCocoaTouchApplication</string>
</array>

Restart the Xcode!

Everything should work fine now:!! And you have Core Data option visible when you Create a new Tabbed Project In Xcode.

Calculate answered 12/1, 2012 at 9:44 Comment(1)
have you tested if the an app using it is working? Because there's something strange in passing managedObjectContext across tab bar view controllersWanderlust
G
6

The templates are designed to be more 'pure', any combination of the templates is left as an exercise for the developer.

They could do a CoreData + Tab and Nav Controller template, but to be fair they'd then have to do every other combination that might be 'reasonable'.

Combining them yourself isn't that hard, and there's sample apps in the dev centre that show some of the combinations within a working application.

Gazelle answered 2/9, 2009 at 4:26 Comment(0)
P
2

Had to do the same, i think the easiest way is to create a "Window-based Application", then declare a tabBarController in your AppDelegate like this:

AppDelegate.h

@interface CommUnityAppDelegate : NSObject <UIApplicationDelegate> {
UITabBarController *tabBarController; // add this
UIWindow *window;
}

// and this
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;

In your MainWindow.xib insert a TabBarController and connect it with your AppDelegates tabBarController.

After that make it visible by adding following line

AppDelegate.m

- (void)applicationDidFinishLaunching:(UIApplication *)application {
  [window addSubview:tabBarController.view]; // add this
  [window makeKeyAndVisible];
}

This gives you a basic set up and from there you can easily add navigation controllers with interface builder

Pluckless answered 2/9, 2009 at 9:1 Comment(3)
Great. That was really useful. Will follow this approach from now on. Cheers, MattCoterie
It's a lot easier to add the tab bar controller to a Core Data project than to add the Core Data stuff to a tab bar project because a lot of Core Data methods and variables in the app delegate are created for you.Tawnyatawsha
Also if you add "@synthesize tabBarController;" to AppDelegate.m it will get rid of a couple warnings.Uncommonly

© 2022 - 2024 — McMap. All rights reserved.