Question

I want to replicate the functionality of the Twitter app where the search bar slides in to the navigation bar.

However I have run into a problem. If I don't add

[self.searchDisplayController setDisplaysSearchBarInNavigationBar:YES];

into viewDidLoad the bar will not appear. I have a search button in the righthand navigation item when I click it I call the above method. Is there anything I can do to ensure the search bar gets drawn.

Was it helpful?

Solution

You can add search bar on navigation bar....

initially in your viewDidLoad:-

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

in your action method

mySearchBar.frame = CGRectMake(0.0, 0, 320, 44);

in viewWillDisappear

[mySearchBar removeFromSuperview];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top