39

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

Community
  • 1
  • 1
vzm
  • 2,440
  • 6
  • 28
  • 47

6 Answers6

78

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];
}
Zoxaer
  • 926
  • 5
  • 3
  • 2
    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 `UIBarButtonItem`s. 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? – Jean-Denis Muys Jun 30 '15 at 12:07
  • 4
    @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. – wpiwonski Jul 13 '15 at 14:01
  • @Jean-DenisMuys Could you please add your final solution as a new answer? Ot would je very helpful to me and other. Thanks – Brabbeldas Oct 15 '15 at 20:11
  • Just used this answer in Xcode8. Thank you @Zoxaer and @wpiwonski! – Polly Jul 12 '17 at 03:12
29

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

Kegham K.
  • 1,589
  • 22
  • 40
  • 2
    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 Feb 21 '16 at 21:43
16

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)
}
Keith Holliday
  • 1,692
  • 21
  • 15
  • 2
    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. – Paul Bonneville Feb 21 '16 at 21:45
11

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!

Josh
  • 6,251
  • 2
  • 46
  • 73
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

Stéphane Bruckert
  • 21,706
  • 14
  • 92
  • 130
David Wong
  • 10,284
  • 3
  • 39
  • 34
1

I used an intermediate View Controller with a Container view to the table. Add the toolbar view to the intermediate, and make it look however you want (use UIButtons instead of UIBarButtonItem).

If you do this, have the container view stretch to the top of the screen and not the bottom of the nav bar or you'll pull your hair out trying to get the scroll insets right.

Some more details in a similar question https://stackoverflow.com/a/31878998/1042111

Community
  • 1
  • 1
Brian Broom
  • 497
  • 4
  • 11