UISearchBar displaysSearchBarInNavigationBar

自闭症网瘾萝莉.ら 提交于 2020-01-03 05:07:13

问题


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

Thanks

Jonathan


回答1:


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];


来源:https://stackoverflow.com/questions/22576803/uisearchbar-displayssearchbarinnavigationbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!