title: I have working search bar, when i move it to navigation bar, it stopped working swift
body: <p>I have search bar with search bar controller and table view and its working.</p>
  
  <p>Image:
  <img src="https://i.stack.imgur.com/vcT0vl.png" alt="enter image description here"></p>
  
  <p>Here is the code:</p>
  
  <pre><code>class SearchViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UISearchDisplayDelegate, UISearchBarDelegate {
  
  @IBOutlet var searchBar: UISearchBar!
  @IBOutlet var tableView: UITableView!
  var friendsArray = [FriendItem]()
  var filteredFriends = [FriendItem]()
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      //var leftNavBarButton = UIBarButtonItem(customView:searchBar)
      //self.navigationItem.leftBarButtonItem = leftNavBarButton
  
      self.friendsArray += [FriendItem(name: "Test1")]
      self.friendsArray += [FriendItem(name: "Test2")]
      self.friendsArray += [FriendItem(name: "Test3")]
  
      self.tableView.reloadData()
  
      //var leftNavBarButton = UIBarButtonItem(customView: searchBar)
      //self.navigationItem.leftBarButtonItem = leftNavBarButton
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }
  
  func numberOfSectionsInTableView(tableView: UITableView) -&gt; Int
  {
      return 1
  }
  
  func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int
  {
      if (tableView == self.searchDisplayController?.searchResultsTableView)
      {
          return self.filteredFriends.count
      }
      else
      {
          return self.friendsArray.count
      }
  }
  
  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell
  {
      let cell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! UITableViewCell
  
      var friend : FriendItem
  
      if (tableView == self.searchDisplayController?.searchResultsTableView)
      {
          friend = self.filteredFriends[indexPath.row]
      }
      else
      {
          friend = self.friendsArray[indexPath.row]
      }
  
      cell.textLabel?.text = friend.name
  
      return cell
  }
  
  
  func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
  {
      tableView.deselectRowAtIndexPath(indexPath, animated: true)
  
      var friend : FriendItem
  
      if (tableView == self.searchDisplayController?.searchResultsTableView)
      {
          friend = self.filteredFriends[indexPath.row]
      }
      else
      {
          friend = self.friendsArray[indexPath.row]
      }
  
      println(friend.name)   
  }
  
  func filterContetnForSearchText(searchText: String, scope: String = "Title")
  {
      println(searchText)
  
      self.filteredFriends = self.friendsArray.filter({( friend : FriendItem) -&gt; Bool in
          var categoryMatch = (scope == "Title")
  
          var stringMatch = friend.name.rangeOfString(searchText)
  
          return categoryMatch &amp;&amp; (stringMatch != nil)
      })
  }
  
  func searchDisplayController(controller: UISearchDisplayController, shouldReloadTableForSearchString searchString: String!) -&gt; Bool   
  {
      self.filterContetnForSearchText(searchString, scope: "Title")
      return true
  }
  
  func searchDisplayController(controller: UISearchDisplayController, shouldReloadTableForSearchScope searchOption: Int) -&gt; Bool
  {        self.filterContetnForSearchText(self.searchDisplayController!.searchBar.text, scope: "Title")
  
      return true   
  }
  }
  </code></pre>
  
  <p>I need to move that search bar to navigation bar, i have to looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/hP0rXl.png" alt="enter image description here"></p>
  
  <p>I found this:</p>
  
  <pre><code>var leftNavBarButton = UIBarButtonItem(customView: searchBar)
  self.navigationItem.leftBarButtonItem = leftNavBarButton
  </code></pre>
  
  <p>But than my searching totally stopped working. I think it loose all preference of searchBar. </p>
  
  <p>Any idea, how can i do this?</p>