How to add a toolbar to the bottom of a UITableViewController in Storyboards?

71,437

Solution 1

if you want show toolbar in one view controller which placed in some navigation controller.

  1. select view controller in storyboard
  2. in utilities, show "attribute inspector". select "bottom bar" style.
  3. add bar button item
  4. add code in view controller, to show and hide toolbar:

code:

- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setToolbarHidden:NO animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [self.navigationController setToolbarHidden:YES animated:YES];
}

Solution 2

Very easy. Just click on the navigation controller. Then in Show Attributes Inspector then navigation controller then click on the shows toolbar. Check the screen shot.

Show Toolbar Screen Shot

Solution 3

For Swift users, you can use the following code:

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated);
    self.navigationController?.setToolbarHidden(false, animated: animated)
}

override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated);
    self.navigationController?.setToolbarHidden(true, animated: animated)
}

Solution 4

This remedy works for (2016) iOS 9.2. We all hate how Apple makes us waste time in stuff that should be straightforward like this. I like step by step solutions for this type of silly problems, so I will share it with you!:

  1. Select your View controller > Attribute Inspector > Select "Opaque Toolbar"
  2. Now, drag and drop a "Bar Button item to your Storyboard.
  3. Select your newly dropped Bar Button Item > Atrribute Inspector > System Icon > Select your favorite icon.
  4. In the viewDidLoad() method of your View controller, add this code before anything else:

    override func viewDidLoad(animated: Bool) {
        self.navigationController?.setToolbarHidden(false, animated: true)
    

    //the rest of code }

  5. You don't want that toolbar hanging around elsewhere, so add this inside your view to hide it once the current window is dismissed:

-

 override func viewWillDisappear(animated: Bool) {
                super.viewWillDisappear(animated);
                self.navigationController?.setToolbarHidden(true, animated: animated)

        }

Voila!

Solution 5

  1. Drag a UIViewController into Storyboard
  2. Drag a UIToolbar on top of the Storyboard's contents.
  3. Drag a UITableView on top of the Storyboard's contents.
  4. Link the tableview's delegate and datasource to your source code.

Although you won't be able to use UITableViewController as your linking class step 4 will allow you to link it to a regular UIViewController.

You'll need something like this in the header though

@interface MyViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>

It'll look something like this in your storyboard:

enter image description here

Share:
71,437
vzm
Author by

vzm

Updated on July 29, 2022

Comments

  • vzm
    vzm almost 2 years

    In my UITableView that I have setup using Storyboards, I need to be able to add a tool bar that sticks to the bottom of the view, it should not scroll.

    Unlike this question: LINK I don't think I could add a TableView subview to a normal view and then just add a toolbar programmatically because I am using dynamic cells which seem a lot easier to integrate via Storyboards.

    For now, this is what I am stuck with.... enter image description here

  • Gajendra Rawat
    Gajendra Rawat about 10 years
    Hey i drag toolbar from Storyboard's contents but it appears in whole screen while i want to add it bottom
  • David Wong
    David Wong about 10 years
    Try set the focus on the bottom bar before adding. Sometimes if you have the view controller selected views won't go in.
  • ConfusedDeer
    ConfusedDeer about 9 years
    @DavidWong The answer by Zoxaer is much more convenient to implement.
  • Jean-Denis Muys
    Jean-Denis Muys almost 9 years
    That many years later, using Xcode 7, I can't implement that answer. In the attributes inspector for the UITableViewController, I selected "Opaque Toolbar" for the "Bottom Bar" setting. I added the UIBarButtonItems. The toolbar and the buttons appear fine in the Storyboard, but don't show up at runtime, though I implemented the 2 overrides as shown. any idea?
  • wpiwonski
    wpiwonski almost 9 years
    @Jean-DenisMuys If you have an UITableViewController embedded in NavigationController you have to select "Opaque Toolbar" for NavigationController, then bottom bar will be visible at runtime.
  • Brabbeldas
    Brabbeldas over 8 years
    @Jean-DenisMuys Could you please add your final solution as a new answer? Ot would je very helpful to me and other. Thanks
  • Paul Bonneville
    Paul Bonneville about 8 years
    This does work in Xcode 7.2.1 iOS 9.2 with Swift. You can turn it on in Interface Builder and also programmatically turn it on and off per view controller in viewWillAppear with the navigationController?.setToolbarHidden() method or by setting navigationController?.toolbarHidden.
  • Paul Bonneville
    Paul Bonneville about 8 years
    This does work in Xcode 7.2.1 iOS 9.2 with Swift. This assumes your view is embedded in a navigation controller of course, which is what the toolbar is actually a part of.
  • Polly
    Polly almost 7 years
    Just used this answer in Xcode8. Thank you @Zoxaer and @wpiwonski!