0

I want to make my search bar stop scrolling along with table view. I tried to add search controller into viewForHeaderInSection and it failed.Also I want to try to show original content while search bar active. So I try to do it in viewDidLoad but I don't know how to make it work. Here is my code for both of method.

    searchController = UISearchController(searchResultsController: nil)
    searchController.hidesNavigationBarDuringPresentation = false
    searchController.searchBar.searchBarStyle = UISearchBarStyle.Prominent
    searchController.searchBar.sizeToFit()
    tableView.tableHeaderView = searchController.searchBar
    definesPresentationContext = true
    searchController.searchResultsUpdater = self
    searchController.dimsBackgroundDuringPresentation = false

Do you have any suggestion?

asiandudeCom
  • 441
  • 1
  • 5
  • 26

2 Answers2

0

Add both the table view and the search view into another view (which becomes the view of your view controller). Then the search view will be completely disconnected from your table view.

Note that if your view controller is currently a table view controller subclass you will need to change that to be a simple view controller subclass.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • Do i need to all over again or just change tableViewcontoller class to ViewController class? – asiandudeCom Aug 12 '15 at 20:11
  • You can modify your existing controller class with protocol conformance, a property for the table and a new outlet connection... – Wain Aug 12 '15 at 20:14
0

You are adding the searchbar to the header view. If you want to keep it above your table you can add it to the navigation controller view. How do I use UISearchController in iOS 8 where the UISearchBar is in my navigation bar and has scope buttons?

Community
  • 1
  • 1
Arno van Lieshout
  • 1,570
  • 1
  • 13
  • 19