title: navigationItem.set_BarButton does not work - swift
body: <p>I am implementing a hidden search bar.</p>
  
  <p>Everything works fine, except the commands which ment to bring back the bar buttons, in the function which hides the search bar.</p>
  
  <p>Also, UISearchBar.showCancelButton does not work too, so I had to implement the cancel button manually. (I have set the delegate for the search bar to self)</p>
  
  <p>Here is the code:</p>
  
  <pre><code>func dismissSearch() {
      searchBar.text = ""
      view.endEditing(true)
      tagSearchResults = [Tag]()
      TagSearchFeed?.collectionView.reloadData()
      searchResultsContainer.isHidden = true
      hideSearchBar() 
  }
  
  
  
  func showSearchBar() {
      searchBar.alpha = 0
      navigationItem.titleView = searchBar
      let cancelButton = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(searchBarCancelButtonClicked))
      cancelButton.tintColor = .white
      navigationItem.setRightBarButton(cancelButton, animated: true)
      navigationItem.setLeftBarButton(nil, animated: true)
      UIView.animate(withDuration: 0.5, animations: {
          self.searchBar.alpha = 1
      }, completion: { finished in
          self.searchBar.becomeFirstResponder()
      })
      self.searchResultsContainer.isHidden = false
  }
  
  func hideSearchBar() {
      navigationItem.setRightBarButton(self.searchButton, animated: true)
      navigationItem.setLeftBarButton(self.menuButton, animated: true)
      UIView.animate(withDuration: 0.3, animations: {
          self.navigationItem.titleView = nil
      }, completion: { finished in
  
      })
  
  }
  
  @objc func searchBarCancelButtonClicked() {
      dismissSearch()
  }
  </code></pre>
  
  <p>How could I fix these issues?</p>