Newbie Question: Adding a navigation\tableView controller into a tabBar view?

Discussion in 'iOS Programming' started by jchildress, Aug 7, 2008.

  1. jchildress macrumors member

    Joined:
    Jul 9, 2008
    #1
    So I'm completely new to Objective-C, about 2 days now, and I have a scripting background with a little bit of C experience. So if this question is way too newbie then I apologize.

    I'm trying to create an app with a 4 button TabBar controller at the bottom, and have two of the tab views be a simple drilldown TableList controller.

    Do I need to make a navigation controller to control the TableList? Or can I just add the TableList to the view of the tab and it will do the drilldown for me?

    And I guess if somebody can suggest a code flow for this idea, that would be great. I'm thinking that I should first create a tabBar program project. then modify the tabBar to have 4 buttons that each point to a simple view. then build upon each of those views.

    Any suggestions or comments would be appreciated.
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    You will most likely want a navigation controller, because that is what allows you to go forward/backwards with different views. But yes, start off with the tab bar, then add in the view controllers (which will probably all be navigation controllers, which in turn contain table view controllers and standard view controllers). Lots of view controllers :)
     
  3. jchildress thread starter macrumors member

    Joined:
    Jul 9, 2008
    #3
    This is where I get confused. let me try to explain what I have going.

    My main app is an NSObject with a window and UITabBarController. I have the tabbar controller setup (in the mainWindow.xib file) in UI builder to use 4 buttons and each button links to a new NIB file. all 4 nib files are are simple UIViewControllers. This works as expected and I assume that the NIB file handles all of the view switching behind the scenes becuase I do not see any code that handles tabbar buttons being pressed.

    So when I want add a drill down to the first tabbar view, I assume that I need to make a navigationController that has a window itself? And I tell the navController to fill in the window with each layer I'm drilling down in? Or does this happen automatically like the tabbar handles the view switching?

    Can anybody point me to some sample code that does this exactly? Apple has a lot of sample code but nothing that does this? At leaset nothing that I can find.
     
  4. nottooshabby macrumors 6502

    Joined:
    Jul 12, 2008
    #4
    I'm struggling with the exact same thing. I got as far as getting my tab bars to bring up a blank table view, but could never get any cells to show up.... If you get this working let me know!
     
  5. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #5
    The tab bar controller handles the buttons for you. You give it view controllers, and it creates the buttons based on these and selects the view controller based on which button is being pressed.

    You will need to make a navigation controller. This handles the bar at the top, its buttons and sliding views from left to right. You need to create view controllers that get pushed and popped from the navigation controller. If you want a table, use a table view controller.

    Apple has tons of code on how to do all of this. Plus they have lots of documentation/guides/tutorials that go in specifics.
     
  6. jchildress thread starter macrumors member

    Joined:
    Jul 9, 2008
    #6
    Can I make one of the tabBar views reference a NIB that has the view, navController, TableList all in the same NIB? or is that not a good idea?

    The NIB file that is loaded by the TabBar, should that be a UIViewController that somehow accesses a navController? OR should I make it a navController from the beggining that then accesses the proper tableLists?
     
  7. nickday macrumors member

    Joined:
    Feb 28, 2008
    Location:
    Manchester, UK
    #7
    Did you get anywhere with this? If so, I'd love to hear how you put all the controllers together :)

    Cheers,
    Nick
     
  8. bones237 macrumors newbie

    Joined:
    Sep 15, 2008
    #8
    i would REALLY like to know if anyone got anywhere with this....PLEASE!!! HELP!! I have been working on this for 3 days now with no result. I have a tab bar controller with 4 tabs. 3 of the tabs are just text fields, labels and whatnot but the fourth tab i need to display a table that retrieves its editable data from a plist. I changed the 4th tab to a navigation controller via IB and i can display section headers, push/pop new view controllers but not a single cell will show up.
    Please anyone???
     
  9. CoreNet macrumors newbie

    Joined:
    Oct 17, 2008
    #9
    Working solution...

    I am trying to do a similar project and here is what I am trying to do and how I finally got it to work. I am fairly new to iPhone development so I cannot attest to how efficient this is, but I can say that it works.

    I have a tab view with 4 tabs each with an external nib file and controller class. Tab #4 is a simple view for an about page describing the application, so I have it set to a regular view.

    Tabs 1 - 3 are set to navigation controller views. To set this in interface builder, double-click on your "MainWindow" nib to pull it up and then SINGLE-click on the tab view controller to select it. Hit "Command-1" to pull up your attributes inspector. This is where you set the assigned controller for each tab's view. Set the ones you want to have a nav bar to have a class of "Nav Controller."

    Now double click the Tab view controller icon to pull it up. Click on tab #1 - it should NO LONGER say it is loading an external NIB, that is ok. Click in the main area where it says, "View". Then hit COMMAND-4 and set the class at the top to match your view controller class.

    As long as each class handles the UITableView information, you should now see each tab have a nav bar with a working table view underneath that does NOT scroll the nav bar out of view.

    Hope this helps!

    John
     
  10. matthew858 macrumors member

    Joined:
    Apr 15, 2008
    Location:
    Sydney, Australia
    #10
    I got this far, thanks for the help. How do I add a table to the Navigation Controller through Interface Builder?
     
  11. Yablargo macrumors newbie

    Joined:
    Jan 4, 2009
    #11
    Thank you! this was driving me nuts! Here I thought hte "hard work" was done creating all of my back-end classes and I was going crazy getting a navigation bar above certain tab windows. woo.

     
  12. sfdoctorp macrumors newbie

    Joined:
    Sep 3, 2009
    #12
    Both Nav Controller & Tab Controller -> but select tabs only!

    Fellow Forum Users,

    I am stumped and would really appreciate someone's help. Basically, I have created an App, using the Tab Bar Controller, that has 6 tabs. Here is the architecture:

    1) MainWindow.xib
    a) Tab Bar Save - App Delegate (referencing UI Window & Tab Bar Controller)
    b) Tab Bar Controller - Each tab loads from a NIB (seperate XIB file), however all tabs have one view controller (called AllTabsController), EXCEPT for one.
    c) Tab 4 - uses RootViewController, which is of type TableViewController, and thus is the only tab that contains a TableView.
    2) TabBarSaveDelegate.h/m - This is of course the main app code, which currently contains the window element and the tab controller. it calls [window addSubview:tabBarControllor.view] in the appDidfinishlaunching function.
    3) 5 basic XIB files - these files all have their views designed in the interface builder, each with unique fields and buttons, and obviously unique button/field handlers. All the handling logic is in AllTabsController.h/m
    4) AllTabsController.h/m - defines all the UITextField and buttons, etc for 5 tabs, and extends the ABPeoplePicker, as three tabs heavily depend on using the Address Book picker on the iphone to pick a content.
    5) ThirdView.xib - (sorry for the poor name), this XIB contains a Tableview element and a searchbar. this is connected to RootViewController - this connection is defined in the interface builder in the ThirdView.xib, as well as as part of the Tab Bar Controller, in the MainWindow.xib.
    6) RootViewController.h/m - contains the code to load the table and carry out searching. The table is loaded from an array - no complicated SQL lite or web services work here.

    7*) DetailViewController.h/m & DetailView.xib - this is basically to support drill down from a selection of a cell in the table view. This however does NOT work for me at this point, because of controller issues, as the design I've downloaded pushes to the Navigation controller stack (as I've seen in all the apps I have with drill down capability).


    ISSUE:
    For my code to work, I need to be able to use the NavigationController, in parallel with the Tab Bar Controller. I have suffered issues with control of the window, having both. What I really need is for the Nav Controller to only appear on the tab with the Table View. This should be possible, as part of the Tab Controller - since I have 6 tabs, there is a More button - it automatically takes me the exact drill down type thing I am looking for.

    The question is - where do I add the Navigation Controller object? Specifically, where should it be instantiated, then do I call [window addSubView] somewhere else? I have tried adding it to MainWindow.xib and instantiating it the in root delegate, but I don't have access to [window] in my RootViewController. Since rootViewController is a controller, I dont think there is anyway to add the NavController there.

    Has anyone ran into this?
     
  13. sfdoctorp macrumors newbie

    Joined:
    Sep 3, 2009
    #14
    this link is helpful in giving me ideas.

    however for whatever reason, the solution doesn't exactly work per the instructions. I am trying it, but all I see is just the empty bar - my tableview doesn't load below it.
     
  14. sfdoctorp macrumors newbie

    Joined:
    Sep 3, 2009
    #15
    the answer is now on this other forum:

    http://www.iphonedevsdk.com/forum/i...bs-only-tabcontroller-primary.html#post122668

    >>>

    You add view controllers to navigation controllers, not the other way around.

    For the tab that needs navigation, in your XIB file that contains the tab bar controller, delete that tab (view controller). Grab a navigation controller from the palette and drag it to the same spot. Crack open the navigation controller, find the view controller inside it, and set that to be your custom view controller class.

    >>>>>

    Perfect! I got it working!

    It took a while, because of the stupid saving tab order option I had enabled. I had to comment that code out.

    For anyone else who needs help with this.

    1) Add a new Tab, by dragging the UINavigationController from the palette.
    2) Drill down into it, on the view controller, set the NIB to be the XIB you were using before.
    3) Change the view controller to be the view controller you were using before.
    4) Discard or move your old tab to the end (rename OLD).

    The above should work straight up.
     

Share This Page