iphone tab bar controller and core data

Sway picture Sway · Sep 2, 2009 · Viewed 10.9k times · Source

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

Answer

Peter Whitfield picture Peter Whitfield · Dec 14, 2009

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