title: iOS, swift, move UISearchBar from tableHeaderView to UINavigationItem
body: <p>I have tableview. In the table view, I have UISearchBar in the tableHeaderView (I defined it in UIStoryBoard).
  I want to move UISearchBar from tableHeaderView to UINavigationItem when I tap to search bar. And I want to return all back when I tap cancel button.</p>
  
  <p>Problem: I cant to return UISearchBar to tableHeaderView.</p>
  
  <pre><code>func moveSearchBarToNavigationBar()
  {
      self.searchBar.removeFromSuperview()
      self.tableView.tableHeaderView = nil
  
      self.navigationItem.titleView = self.searchBar
      self.navigationItem.leftBarButtonItem = nil
  }
  
  func moveSearchBarToTableHeader()
  {
      self.searchBar.removeFromSuperview()
      self.tableView.tableHeaderView = self.searchBar
  }
  
  func searchBarTextDidBeginEditing(searchBar: UISearchBar)
  {
      self.searchActive = true
      self.searchBar.showsCancelButton = true
  
      self.moveSearchBarToNavigationBar()
  }
  
  
  func searchBarCancelButtonClicked(searchBar: UISearchBar)
  {
      self.searchActive = false
      self.searchBar.showsCancelButton = false
      self.searchBar.text = ""
      self.searchBar.resignFirstResponder()
      self.searchBar(self.searchBar, textDidChange: "")
  
      self.moveSearchBarToTableHeader()
  }
  </code></pre>
  
  <p>First view (normal):
  <img src="https://i.stack.imgur.com/etbWP.png" alt="enter image description here"></p>
  
  <p>When I tap on search bar(normal):
  <img src="https://i.stack.imgur.com/nwoV2.png" alt="enter image description here"></p>
  
  <p>When I tap on cancel button (not normal):</p>
  
  <ol>
  <li>I need only search bar view correction (do not worry about navigation bar)</li>
  <li>I want to deselect search bar when cancel button function execute (without self.moveSearchBarToTableHeader() (and self.moveSearchBarToNavigationBar()) - search bar deselect, but within - not)
  <img src="https://i.stack.imgur.com/PWvaW.png" alt="enter image description here"></li>
  </ol>