title: Swift - Custom SearchController and SearchBar
body: <p>I am trying to recreate the search field as seen in the Yahoo Finance app. I followed an online tutorial for customizing the UISearchBar and UISearchController, however I still have some problems. If any of you could open up my project and see where Im going wrong / where I need to add these lines with even one of these that would be really great.</p>
  
  <p>My attempted solution project can be found here: <a href="https://github.com/jordanw421/yahoofinance" rel="nofollow noreferrer">https://github.com/jordanw421/yahoofinance</a> </p>
  
  <hr>
  
  <p>1) How to get the search bar active (with text to the left, and typing indicator blinking) as soon as view presents itself? In the link below, you can see what I am talking about, when the button is pressed the search view is loaded and the search bar is instantly active. </p>
  
  <p><a href="https://youtu.be/tRtXm-m1hX0" rel="nofollow noreferrer">https://youtu.be/tRtXm-m1hX0</a></p>
  
  <p>I tried using:</p>
  
  <pre><code>customSearchController.definesPresentationContext = true
  customSearchController.isActive = true
  customSearchController.searchBar.becomeFirstResponder()
  </code></pre>
  
  <p>but that didn't work. Should I be setting these in the initial view controller with prepareForSegue? </p>
  
  <hr>
  
  <p>2) How to set the keyboard appearance (to dark), and to add a keyboard toolbar with a button? </p>
  
  <p>I was able to get this working for a non-custom search bar, but for some reason these don't work now:</p>
  
  <pre><code>customSearchController.searchBar.keyboardAppearance = .dark
  </code></pre>
  
  <p>and</p>
  
  <pre><code>func addKeyboardButton() {
  
      let keyboardToolbar = UIToolbar()
      keyboardToolbar.sizeToFit()
      keyboardToolbar.isTranslucent = false
      keyboardToolbar.barTintColor = UIColor.blue
  
      let addButton = UIButton(type: .custom)
      addButton.frame = CGRect(x: keyboardToolbar.frame.size.width / 2, y: keyboardToolbar.frame.size.height / 2, width: 50, height: 30)
      addButton.addTarget(self, action: #selector(clickMe), for: .touchUpInside)
      let item = UIBarButtonItem(customView: addButton)
      keyboardToolbar.items = [item]
  
      customSearchController.searchBar.inputAccessoryView = keyboardToolbar
  }
  </code></pre>
  
  <p>and calling, </p>
  
  <pre><code>addKeyboardButton()
  </code></pre>
  
  <p>in the search bar configure function.</p>
  
  <hr>
  
  <p>3) How to prevent the search bar / table view header from scrolling, but still allow the tableView to scroll?</p>
  
  <p>If you look at my attempted solution you can see that for some reason the tableview header scrolls with the table view. When I use a non-custom search bar the header remains static. </p>
  
  <hr>
  
  <p>I know there are a lot of questions here, but I've been stuck on this for awhile and could really use some help. Thank you. </p>