Beginner: How to add top bar with buttons on UITableViewController

11,327

Solution 1

When you create the UITableViewController, do the following:

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:tableViewController];

and then instead of setting the table view controller as the view, set it to the navigation controller. Inside your table view controller, you can set the left and right buttons for the navigation bar to UIBarButtonItems (ask me if you want to know how to do that).

Solution 2

Select your UITableViewController and go Editor > Embed In and choose a navigation controller.

Solution 3

You might look at using the UINavigationController. https://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UINavigationController_Class/Reference/Reference.html

If you do not want to use UINavigationController, then what you could do is create a view that has the "top bar" that you are looking for, then add the UITableViewController's view to your new UIView.

Share:
11,327
user836026
Author by

user836026

Updated on June 15, 2022

Comments

  • user836026
    user836026 almost 2 years

    I'm new to iOS development, I just have UITableViewController in a storyboard. I would like to add a top bar to it with some buttons, how to do that?

    Notice, I'm using UITabBar that is created by "Storyboard" and my ITableViewController is one item of the UITabBar.

  • beryllium
    beryllium about 12 years
    Why not a UITableViewController? It's the same thing as UIViewController and already has table view
  • user836026
    user836026 about 12 years
    Thanks ... the issue I don't inistiante the UITableViewController. i have the UITableViewController as item on UITabBar and the UITabBar is created by storyboard, so how could I tell the storyboard to use UINavigationController instead, and than I create UINavigationController with UITableviewcontroller ... i'm a bit confused.
  • user836026
    user836026 about 12 years
    So could i just add a "top bar" to my UITableViewController?
  • jrtc27
    jrtc27 about 12 years
    Select your UITableViewController and go Editor > Embed In and choose a navigation controller. You should get something like this developer.apple.com/library/ios/releasenotes/Miscellaneous/…
  • jrtc27
    jrtc27 about 12 years
    You could, but it would get a bit hacky.
  • Sam
    Sam over 10 years
    @beryllium i believe this is because a UITableViewController's View is by default the tableview