1

I am using UISearch bar controller enter image description here

after I press on it disappear like this enter image description here

my code :

let searchController = UISearchController(searchResultsController: nil)


override func viewDidLoad() {
    super.viewDidLoad()

    // MARK: - Search
    searchController.searchBar.delegate = self
    navigationItem.titleView = searchController.searchBar

}
func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
presentViewController(searchController, animated: true, completion: nil)

}
Rajesh
  • 10,318
  • 16
  • 44
  • 64
Sam
  • 243
  • 3
  • 12
  • Why are you calling "presentViewController(searchController, animated: true, completion: nil)" on text did begin editing...? – Roy K Aug 18 '16 at 07:46
  • 1
    @RoyK even If I do not call it I have the same problem – Sam Aug 18 '16 at 07:48

2 Answers2

2

try this

self.searchController.hidesNavigationBarDuringPresentation = NO
self.definesPresentationContext = NO

or use this

func willPresentSearchController(searchController: UISearchController)     {
self.navigationController.navigationBar.translucent = true
}

func willDismissSearchController(searchController: UISearchController) {
self.navigationController.navigationBar.translucent = false
}

for additional Help see this link

Community
  • 1
  • 1
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
0

Try to set this property of Viewcontroller

self.definesPresentationContext = NO
Rajesh
  • 10,318
  • 16
  • 44
  • 64