Avijit Nagare
Avijit Nagare

Reputation: 8802

Search bar does not appear in ios

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.

enter image description here

Upvotes: 0

Views: 787

Answers (1)

Vidhyanand
Vidhyanand

Reputation: 5369

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.

Upvotes: 1

Related Questions