Search bar does not appear in ios

旧时模样 提交于 2020-01-07 03:54:10

问题


I have page controller in which I added two tableviews. In each header of tableview search controller added, also viewForHeader method return "Recent" and "Other" view's.

My problem is the search bar does not appear when the search bar clicked. It appear to move up, I cant see what I am typing there. There may be the possibility that the search bar is hidden behind "Connection","Message" tab.

How to keep search bar at same position when keyboard become first responder? any help will appreciated.


回答1:


Have u used below lines of code at ViewDidLoad

if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
    self.edgesForExtendedLayout = UIRectEdgeNone;

[self.view bringSubviewToFront:searchBarRef]; // add this line where ever u need..!

-(void)loadSearchBar {

    searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 64)];
    searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
    searchDisplayController.delegate = self;
    searchDisplayController.searchResultsDataSource = self;

    self.tableView.tableHeaderView = searchBar; 

}

Call this loadSearchBar method at ViewDidLoad.

This will add search bar to TableView.



来源:https://stackoverflow.com/questions/34312614/search-bar-does-not-appear-in-ios

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