title: UISearchBarDelegate methods not being called
body: <p>I had a working search bar and out of nowhere I stopped being able to even to activate any delegate methods. I created the search bar programmatically.</p>
  
  <p>Here is my initialization code: </p>
  
  <pre><code>    self.searchBar.delegate = self
      self.searchBar.translatesAutoresizingMaskIntoConstraints = false
      self.searchBar.searchBarStyle = .minimal
      self.searchBar.isUserInteractionEnabled = true
      let image = self.getImageWithColor(color: UIColor(red: 255/255.0, green: 255/255.0, blue: 255/255.0, alpha: 0.19), size: CGSize(width: self.customNavBar.frame.width * 0.9440, height: self.customNavBar.frame.height * 0.47727))
      searchBar.setSearchFieldBackgroundImage(image, for: .normal)
      self.customNavBar.addSubview(self.searchBar)
      var horizCenter = NSLayoutConstraint(item: self.searchBar, attribute: .centerX, relatedBy: .equal, toItem: self.customNavBar, attribute: .centerX, multiplier: 1, constant: 0)
      var vertConstraints = NSLayoutConstraint(item: self.searchBar, attribute: .top, relatedBy: .equal, toItem: self.customNavBar, attribute: .top, multiplier: 1, constant: 30)
      var widthConstraint = NSLayoutConstraint(item: self.searchBar, attribute: .width, relatedBy: .equal, toItem: self.customNavBar, attribute: .width, multiplier: 0.9440, constant: 0)
      var heightConstraint = NSLayoutConstraint(item: self.searchBar, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: self.customNavBar.frame.height * 0.47727 )
      NSLayoutConstraint.activate([horizCenter, vertConstraints, widthConstraint, heightConstraint])
  </code></pre>
  
  <p>Here is the getImageWithColor method I referenced above: </p>
  
  <pre><code>func getImageWithColor(color: UIColor, size: CGSize) -&gt; UIImage {
      let rect = CGRect(x:0, y:0, width:size.width,height: size.height)
      let path = UIBezierPath(roundedRect: rect, cornerRadius: 5.0)
      UIGraphicsBeginImageContextWithOptions(size, false, 0)
      color.setFill()
      path.fill()
      let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
      UIGraphicsEndImageContext()
      return image
  }
  </code></pre>
  
  <p>And I continue to customize the textField inside the searchBar: </p>
  
  <pre><code>    UITextField.appearance().tintColor = UIColor.white
      let cancelButtonAttributes: NSDictionary = [NSForegroundColorAttributeName: UIColor.white, NSFontAttributeName : UIFont(name: "Gotham-Book", size: 14.0)!]
      UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes as? [String : AnyObject], for: UIControlState.normal)
      let textFieldInsideSearchBar = self.searchBar.value(forKey: "searchField") as? UITextField
      textFieldInsideSearchBar?.textColor = UIColor(red: 255/255.0, green: 255/255.0, blue: 255/255.0, alpha: 1.0)
      textFieldInsideSearchBar?.font = UIFont(name: "Gotham Medium", size: 20.0)
      textFieldInsideSearchBar?.clearsOnBeginEditing = true
      textFieldInsideSearchBar?.borderStyle = .none
      textFieldInsideSearchBar?.clearButtonMode = .whileEditing
      textFieldInsideSearchBar?.isUserInteractionEnabled = true
  </code></pre>
  
  <p>And all my delegate methods: </p>
  
  <pre><code>extension ListViewController : UISearchBarDelegate {
  
  
  func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
  
      print("\nfunc searchBarTextDidBeginEditing\n")
      self.hideDayDropDown()
      UIView.animate(withDuration: 0.25) {
          self.dayButton.alpha = 0.0
          self.dayButtonLabel.alpha = 0.0
          self.dayDropDownArrow.alpha = 0.0
          self.mapButton.alpha = 0.0
          self.mapButton.isEnabled  = false
          self.dayButton.isUserInteractionEnabled = false
          self.tableView.transform = CGAffineTransform(translationX: 0.0, y: -(self.tableView.frame.minY - self.customNavBar.frame.maxY))
  
  
          self.tableView.translatesAutoresizingMaskIntoConstraints = true
          self.tableView.frame = CGRect(x: 0, y: self.customNavBar.frame.maxY, width: self.view.frame.width, height: 300)
  
          self.dealOfTheDayLabel.alpha = 0.00
          self.exploreSpecialView.alpha = 0.0
          self.exploreSpecialsLabel.alpha = 0.0
  
  
      }
      searchActive = true
      self.searchBar.setShowsCancelButton(true, animated: true)
  
      UIView.animate(withDuration: 0.25) {
          self.searchIconImage.alpha = 0.0
          self.searchIconWhileEditing.alpha = 1.0
      }
  }
  
  func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
      print("\nfunc searchBarTextDidEndEditing\n")
      UIView.animate(withDuration: 0.25) {
          self.dayButton.alpha = 1.0
          self.dayButtonLabel.alpha = 1.0
          self.dayDropDownArrow.alpha = 1.0
          self.dayButton.isUserInteractionEnabled = true
  
          self.searchIconImage.alpha = 1.0
          self.searchIconWhileEditing.alpha = 0.0
          self.tableView.transform = CGAffineTransform(translationX: 0.0, y: 0.0)
  
          self.tableView.translatesAutoresizingMaskIntoConstraints = false
          self.mapButton.alpha = 1.0
          self.mapButton.isEnabled  = true
  
          self.dealOfTheDayLabel.alpha = 1.0
          self.exploreSpecialView.alpha = 1.0
          self.exploreSpecialsLabel.alpha = 1.0
      }
      searchActive = false
  }
  
  func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
      print("\nfunc searchBarCancelButtonClicked\n")
      self.searchBar.setShowsCancelButton(false, animated: true)
      self.searchBar.text = ""
      self.searchBar.resignFirstResponder()
      searchActive = false
      self.searchIconImage.alpha = 1.0
      self.searchIconWhileEditing.alpha = 0.0
      self.dayDropDownArrow.alpha = 1.0
      self.tableView.transform = CGAffineTransform(translationX: 0.0, y: 0.0 )
      self.dealOfTheDayLabel.alpha = 1.0
      self.exploreSpecialView.alpha = 1.0
      self.exploreSpecialsLabel.alpha = 1.0
      tableView.reloadData()
  }
  
  
  func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
      self.searchResults = self.library.filter({ (bar: BarLibrary) -&gt; Bool in
          let tmp: String = bar.name!
          let range = tmp.localizedLowercase.range(of: searchText.localizedLowercase)
          return range != nil
      })
      if(self.searchResults.count == 0){
          searchActive = false
      } else {
          searchActive = true
      }
      self.tableView.reloadData()
  }
  }
  </code></pre>
  
  <p>Here is also an image from my interface capture of my navigation bar with the search bar: </p>
  
  <p><img src="https://i.stack.imgur.com/k8zdd.png" alt="Screen Capture Image">  </p>
  
  <p>Screen Capture Image as seen in Interface Capture: View names from front to back: <code>UITextFieldBorderView</code>, <code>UISearchBarTextField</code>, <code>UIView</code>, <code>UISearchBar</code></p>
  
  <p><strong>Note</strong> I'm not sure what the <code>UIView</code> right before the <code>UISearchBar</code> is for</p>
  
  <p>I understand there are a lot of questions on SO about why others can't access their <code>UISearchBar</code> delegate methods. None of those solutions have worked for me. Why can't I access my delegate methods thus far? </p>