Search code examples
iosuitableviewcore-datauinavigationcontrollernsfetchedresultscontroller

A Tabbed application with a different Master Detail Table View on each tab, using Core Data


I was hoping someone could help a noobie out.

I am trying to create an iPhone/iPad app that uses tabs as its main navigation. The first tab will be kind of a home screen with basic info and a feedback button etc. The other tabs (3-4 tabs) each need to display a different "section" of the app. Each section will display a table view and navigation controller (using Core Data). These table views are unrelated to each other, each using different tables from the database (sqlite).

To illustrate this lets say tab 1 is the apps Home, tab 2 lists your grocery list, tab 3 lists recipes and tab 4 lists coupons available. They all fit together in the app but they come from completely different tables. Each navigation controller that appears on each tab is Completely different. Im using it like secondary navigation within the tab.

So my question is, does anyone have any tutorials that illustrates this technique? And if not do I have to create a different fetchedResultsController for each tab? I started the project using the Tabbed application template, I then created another dummy project using the master detail template and added the master detail code and xibs to my tabbed project. So I now have tabs that display the generic time stamp entity that comes with the master detail template however I cannot seem to get the tabs to display different data.

Also how can I create a navigation controller for each table view / tab? All of the documentation says to initialize it inside of the AppDelegate however if I put it there how can I get a different controller for each tab? Do I declare 3-4 controllers in the app delegate and some how assign them to each table view? I have not seen an example of this anywhere even though it makes sense. Tutorials would be much appreciated.

Thank you so much in advance. Im just stuck here. :(


Solution

  • So to start off each tab (I assume you're talking about a UITabBarController) will have it's own UINavigationController->UIViewController. I don't know of any tutorials about using the master-detail inside a tab and I haven't done it personally, but for your second question about navigation controllers inside your tab you would do the following:

    Start off using a tab template using storyboard.

    Inside your storyboard you can see that they have the two view controllers and they are tied in and stuff. I would just delete them as they aren't needed.

    From the right side you'll drag in however many UINavigation controllers (the gold ones) you need. When you drag it in it should bring in two views, the controller and the root view.

    From the tab bar controller control+drag to the navigation controller and connect it to Relation-view controllers. Do this for all the navigation controllers

    Your storyboard should look somewhat like this:enter image description here

    You now have all view structure set up. So you'll now need to create all the classes for those. As you mentioned you'll create a recipe view controller, shopping list view controller...

    Set the blank views to use the classes you just created created. From each of these classes you can push views to their navigation controller and it will push it onto that stack and if you switch tabs you'll start where that one left off.

    Inside of each of these Classes there will need to be a NSfetchedResultsController that will tie into acore data database (Housed in the delegate or another class) and control that table.

    Here is a great tutorial I've used for setting up my first nsfetchedresultscontroller. It goes through the entire process from start to finish.

    http://www.raywenderlich.com/999/core-data-tutorial-how-to-use-nsfetchedresultscontroller

    I hope that gets you off your stuck phase. let me know if there is anything unclear on the set up.