2

I have a Search Bar working fine created like this for my UITableView Class shown below,

 class customTableViewController: UITableViewController,              UISearchResultsUpdating
{....
override func viewDidLoad() {
    super.viewDidLoad()

self.resultSearchController = ({
        let controller = UISearchController(searchResultsController: nil)
        controller.searchResultsUpdater = self
        controller.dimsBackgroundDuringPresentation = false
        controller.searchBar.sizeToFit()
        controller.hidesBottomBarWhenPushed = false
        controller.hidesNavigationBarDuringPresentation = false
        controller.searchBar.searchBarStyle = UISearchBarStyle(rawValue: 2)!

        self.tableView.tableHeaderView = controller.searchBar

        return controller
    })()
    self.tableView.reloadData()
    }
}

It works fine, it's just that when I segue to another view controller, the image of the search bar remains drawn on my screen no matter what view controller I'm in. When I try "searchBar.active = false", I get nil errors.

What can I do so this searchBar is only drawn on this one tableViewController and nowhere else in my navigation?

Thanks a ton.

Woohoopy
  • 303
  • 1
  • 3
  • 9

1 Answers1

0

I've found a bit of a work around, In my prepareToSegue, I said:

   self.resultSearchController.searchBar.hidden = true
   self.resultSearchController.view.endEditing(true)

That's it, and in the destinationViewController I wrote the code below to recognize that its returning to the originalViewController and to redraw the bar.

override func viewWillDisappear(animated: Bool) {
    ....
    resultSearchController.searchBar.hidden = false
}
Woohoopy
  • 303
  • 1
  • 3
  • 9