I have an app designed with storyboards. I'm trying to add a tab bar at the bottom of the view where i have my uitableviewcontroller , problem is it automatically drags it under the first cell .

I intend to add 4 buttons on the tab bar each performing a certain action INSIDE this view ( each one will reload the table with different data from the web ) .

有帮助吗?

解决方案

From your description, UIToolBar would be the best option for you. You would place it at the bottom of your view controller and create IBActions for each button that update your data.
If you are intent on using a UITabBar, then you need to rethink your storyboard layout. You would have a UITabBarController as the initial view, which would have your TableViewController subclass as the root view. You can either make four separate TableViewController subclasses (each for a different dataset) or you can have a single subclass that receives a load message from the UITabBarController on what dataset to load.
If you decide to use a toolbar, it isn't possible to add it to the bottom of a default Interface Builder TableViewController. Follow these steps to add a toolbar to the bottom of your TableViewController subclass:

  1. Insert a UIViewController into the storyboard (this will replace your UITableViewController)
  2. Set the class of your new UIViewController to your UITableViewController subclass (Identity Inspector)
  3. Insert a UIToolbar at the bottom of your new UIViewController and add buttons, IBOutlets, and IBActions as desired.
  4. Add a UITableView to your UIViewController that takes up the rest of the screen space.
  5. In the connections inspector, connect the dataSource and delegate of your UITableView to your UITableViewController subclass
  6. Add and configure as many prototype TableViewCells as necessary.

This should be all that is necessary to get a toolbar in your TableViewController. It requires extra configuration in the Interface Builder, but it is the only way to do it without writing extra code.

其他提示

Select your controller then menu Editor > Embed In > Tab Bar Controller

EDIT : hu i did not read your question entirely. Others answers are more correct.

I intend to add 4 buttons on the tab bar each performing a certain action INSIDE this view ( each one will reload the table with different data from the web ).

As per your last sentence, I have judged that you neither need a tab bar nor tableviewcontroller. You just need a simple View controller having a Tableview at top, and toolbar at bottom. Toolbar would have a segment control with 4 sections - which will act as four buttons. On each section tap, you can capture event of value changed, and load new data in table according to selected index.

It's an easy way of doing thing. Don't make your life complex by using tab bar :)

Ok so this is what i eventually did. I was getting an error in the method mentioned by user2105505 ( marked as correct) , so i decided to create a UIVIEWCONTROLLER and add my tableviewcontroller as a child of that uiviwewcontroller (by importing the uitableviewcontroller class , creating an isntance of the class and instantiating on self.storyboard) , then added the toolbar to the uiviewcontroler.

Then just add the tableview as a subview of the uiviewcontroller view , BUT you need to remember to do two things.

Instantiate your toolbar, and modify the size of the tableview so it fits and the toolbar shows.(maybe use bringToFront as an alternative?didn't work for me, had to specify the size manually ).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top