Beginner: How to add top bar with buttons on UITableViewController
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 UIBarButtonItem
s (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.
user836026
Updated on June 15, 2022Comments
-
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 about 12 yearsWhy not a UITableViewController? It's the same thing as UIViewController and already has table view
-
user836026 about 12 yearsThanks ... 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 about 12 yearsSo could i just add a "top bar" to my UITableViewController?
-
jrtc27 about 12 yearsSelect 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 about 12 yearsYou could, but it would get a bit hacky.
-
Sam over 10 years@beryllium i believe this is because a UITableViewController's View is by default the tableview