Reputation: 2450
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....
Upvotes: 39
Views: 73924
Reputation: 6393
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!:
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 }
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!
Upvotes: 11
Reputation: 1614
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.
Upvotes: 29
Reputation: 1732
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)
}
Upvotes: 17
Reputation: 497
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
Upvotes: 1
Reputation: 10294
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:
Upvotes: 5
Reputation: 926
if you want show toolbar in one view controller which placed in some navigation controller.
code:
- (void)viewWillAppear:(BOOL)animated
{
[self.navigationController setToolbarHidden:NO animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated
{
[self.navigationController setToolbarHidden:YES animated:YES];
}
Upvotes: 78