4

I have set the search controller of my navigation item, so that the search bar is positioned at the top of the screen. What I want to happen is that the search bar is in the 'title view' position like what used to happen on iOS 10. However, the search bar is moved down to make space for a large title for the view controller. How can I hide this extra space?

navigationItem.searchController = searchController
Rashwan L
  • 38,237
  • 7
  • 103
  • 107
Tometoyou
  • 7,792
  • 12
  • 62
  • 108
  • Are you looking for `navigationController?.navigationBar.prefersLargeTitles = false`? – Michael Sep 24 '17 at 20:23
  • @Michael No I don't want the title to appear at all, so all I want is a search bar in the navigation bar and nothing else. – Tometoyou Sep 24 '17 at 20:27
  • You are adding a navigation controller. If you don't want it, why don't you add the UISearchBar directly to the view and not to the navigationController? – Michael Sep 24 '17 at 20:31
  • I need there to be a navigation controller because I press on table view cells. – Tometoyou Sep 24 '17 at 20:35
  • So you are looking for `self.navigationController?.navigationBar.isHidden = true`? – Michael Sep 24 '17 at 21:24
  • 1
    Did you manage to find a solution? I am seeing the same problem, it does not seem to be possible to have the searchBar in place of the title. – fishinear Nov 06 '17 at 13:45
  • Yeah it’s not possible I don’t think. I just stuck with a large title in the end. If you find a solution do let me know! – Tometoyou Nov 08 '17 at 09:42

1 Answers1

0

Sorry for a late reply, but try the following

navigationItem.titleView = searchController.searchBar

instead of navigationItem.searchController = searchController. Hope it will help!

kot331107
  • 437
  • 1
  • 5
  • 9