Take the 2-minute tour ×

noob question regarding ios development.

In a previous project, I have a UITableViewController, to which I am adding a button in the viewDidLoad method, like this:

UIBarButtonItem *button = [[UIBarButtonItem alloc]
self.navigationItem.rightBarButtonItem = button;
[button release];

This works great.

I now have another application in which I am trying to do the same thing, except now I have a UITabBarControllerDelegate at the top (the default that comes along with "Tab Bar Application"), whose first view is the UITableViewController.

The First View has no nib as it's just a table. I am trying to do the same thing with the same code, trying to add a button in the viewDidLoad method, but it's not working.

So in the firstViewController (which is a UITableViewController) I am adding the above code to the viewDidLoad method, with no success.

It is showing data in the table, however (from a managedObjectContext). I've also tried putting the code in the "initWithStyle" method of the firstViewController but that doesn't work either.

Any ideas? Clearly I'm not understanding something.


share|improve this question
Why would you add a button on the Delegate ? Add the button to the First View. –  Legolas Jun 6 '11 at 16:23
I think this is what I'm doing. I'm adding it to FirstViewController (which is a UITableViewController). Or is that incorrect? –  scottlabs Jun 6 '11 at 16:24

2 Answers 2

up vote 0 down vote accepted

Do this.

  1. Create the Tab Bar Controller and set it as your rootController.

    //You will not have three tabs and you need three view controllers//
  2. Set your First View controller as a Navigation View controller.

    // You will now have the Navigation bar at the top//
  3. Create a new file which is a subclass of the UITableViewController.

    // set this as your delegate and datasource for your table view controller methods//
    // pull a table view controller inside the Navigation View Controller as mentioned in (2) & you will have a tableview and navigation view in FirstViewController. Similarly work with the other two tabs

If you have any more doubts; please watch this tutorial on how to do all of these.


share|improve this answer
Fantastic! Thanks for the tip –  scottlabs Jun 6 '11 at 20:14

If i'm not mistaken you need to have your UITableViewController within a UINavigationController in order to show UIBarButtonItems.

share|improve this answer

Your Answer


