1

Current status Current Status

I am doing it programmatically. I also tried to set it into TitleView, but it's not working. Code below:

        //searchBar
    let searchController = UISearchController(searchResultsController: nil)
    searchController.searchResultsUpdater = self
    searchController.obscuresBackgroundDuringPresentation = false
    searchController.searchBar.placeholder = "Search Players"
    navigationItem.searchController = searchController
    navigationItem.hidesSearchBarWhenScrolling = false
    definesPresentationContext = true

I also have a ScopeBar under the searchBar, when selected. If I do it like:

searchController.titleView = searchController.searchBar 

It goes in place, but I cannot select/tap the searchBar anymore.

dan
  • 77
  • 1
  • 10

3 Answers3

0

For me, your example works well, but maybe you canuse it.

   navigationItem.titleView = searchController.searchBar

You can insert search bar into navigation like here. Can you explain what's wrong with search bar in table view header? What isn't work?

Anton Rodzik
  • 781
  • 4
  • 14
  • Thanks. .titleView is working but the search bar becomes not selectable. I Will add details on the question. – dan Sep 18 '18 at 14:46
  • It's very strange behavior, maybe something wrong with navigation bar, need to see more details. – Anton Rodzik Sep 18 '18 at 15:01
0

if your iOS version greater than ios11 or equal you should add like this

navigationItem.searchController = searchController

else

navigationItem.titleView = searchController.searchBar

and also you should give more detail

Cenk Işık
  • 85
  • 1
  • 9
  • thanks. The problem is that when I make it equal to .titleView, the searchBar goes into place, but cannot be selected anymore and it's not working. – dan Sep 18 '18 at 14:50
0

One way to go would be using the bounds to set it to center manually. But on the searchbar activation(click) it would be again messed up and needed to be set again.

searchController.searchBar.bounds=CGRectInset(searchController.searchBar.frame, 0.0f, -2.5f);