2

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.

Dima
  • 8,586
  • 4
  • 28
  • 57

1 Answers1

2

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.

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
  • 1
    Vote up for this answer. `UISearchDisplayController` is totally broken in iOS7. I implemented own alternative of UISearchDisplayController with `UISearchBar` – Vitaly S. Feb 04 '14 at 20:17
  • i already thought about it, but i really dont want to change my app... im looking for this solution... – Dima Feb 04 '14 at 21:27
  • anyway, i did as you said even this is not what i wanted. but i cant get this 50 points back, so enjoy :) – Dima Feb 04 '14 at 23:09
  • @DimaGoltsman Any reason why not? It really isn't that hard, and your changes would be minimal. Add another table on top of the other, hide it, and show it once user enters the search bar. There you can show your cached results or search results. – Léo Natan Feb 04 '14 at 23:10
  • yeah thats what i did... but i can give you the 50 points only in 17 hours :) – Dima Feb 04 '14 at 23:21