Search code examples
iosuiviewcontrolleruinavigationbarsearchbarsearchdisplaycontroller

uiviewcontroller with navigation bar does not display searchBar in navigation bar


I have a UIViewController with NavigationBar. I'm trying to place a searchBar in it with the following code:

self.searchDisplayController.displaysSearchBarInNavigationBar=YES;

The code has worked on my previous UIViewController, the difference is that one is embedded in a NavigationController where this is a modal segue, thus the need to manually place the NavigationBar in it.

What am I missing to get this to display in the NavigationBar?


Solution

  • You can add serchbar on navigation bar like that:

    mySearchBar.frame = CGRectMake(0.0, -80.0, 320.0, 44.0);
    [self.navigationController.navigationBar addSubview:mySearchBar];