title: How to show/hide UISearchBar by action in Swift?
body: <p>I have a <code>UITableView</code> with a <code>UISearchBar</code>. I need to show/hide my <code>searchBar</code>, by user action (button pressing):</p>
  
  <p>I tried to use this code: </p>
  
  <pre><code>if self.tableView.contentOffset.y == 0 {
      self.tableView.contentOffset = CGPoint(x: 0.0, y: self.searchBar.frame.size.height) 
  }
  </code></pre>
  
  <p>from <a href="https://stackoverflow.com/questions/1081381/iphone-hide-uitableview-search-bar-by-default">this</a> question.
  Actually I've tried all of those answers. All of them just scroll my <code>UITableView</code>, and each time I'm scrolling my <code>UITableView</code> - <code>searchBar</code> appears.
  I tried to do something like this:</p>
  
  <pre><code>self.newsTableView.tableHeaderView = nil; //Hide 
  </code></pre>
  
  <p>and</p>
  
  <pre><code>self.newsTableView.tableHeaderView = self.SearchBar; //Show
  </code></pre>
  
  <p>But <code>UITableView</code> doesn't want to return <code>searchBar</code>;</p>
  
  <p>How can I resolve this problem?
  I need to hide <code>searchBar</code> by action, not to scroll my <code>UITableView</code> (hide like <code>searchBar.hidden = true</code>) Actually, <code>searchBar.hidden = true</code> works, but there is a white space instead of <code>searchBar</code>.</p>