Question

I need to implement search history. so what i want to do is display the history in the search display controller when no text entered yet.

I implemented this:

-(void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller{
    self.searchDisplayController.searchResultsTableView.hidden=NO;
}

and also this:

- (void)searchDisplayController:(UISearchDisplayController *)controller didHideSearchResultsTableView:(UITableView *)tableView{
  self.searchDisplayController.searchResultsTableView.hidden=NO;
}

to make the table be shown always.

I also implemented the number of rows to distinct the cases: (i also took care of cellForIndexpath, but no need to show it here)

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if ([self.searchDisplayController.searchBar.text isEqualToString:@""]) {
    NSArray* d=[DropsAppDelegate getSharedInstance].userData.getLastSearches;
    return d.count;
}
return [searchResultPlaces count];
}

but this makes a mess. The table is shown but behind the half transparent screen and become visible when exiting the search. the history results

and also that screen does not comes off when i actually type something. what can i do to make the UITableView always be shown? I looked at all the answers but nothing works for iOS7.

Was it helpful?

Solution

It seems like you are fighting UISearchDisplayController, which has always been somewhat grudgy, and more-so on iOS7.

My suggestion is to not use it but implement what you need with a search bar. It's really not that difficult, you get delegate callbacks with everything you need, and you don't fight the technology. The UISearchBarDelegate tells the whole tale.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top