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

前端 未结 6 1945
温柔的废话
温柔的废话 2020-12-04 14:21

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.

6条回答
  •  再見小時候
    2020-12-04 15:15

    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!

提交回复
热议问题