this is my storyboard view and it's connections:
http://i.stack.imgur.com/uD0pT.png http://i.stack.imgur.com/FNnVa.png
In my specific case I have the searchResultsTableView that gets its data from the first external web service and the self.tableview that fetches data from another web service.
I add some code to be clear:
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { ... }
this fetched the first web services, in particular return NO
and there is a:
[self.searchDisplayController.searchResultsTableView reloadData];
to reload the data when the fetch is completed.
Then we have:
-(void) doSearch:(NSString*) keyword inStore:(NSInteger) store getPage: (int) pagenum {..}
that fetches the second web service and set the results in an array called 'fetchedItems'
Now, to manage this two tables I had to write this method:
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
NSLog(@"Avvio ricerca..");
// Do the search...
NSInteger store = [self buttonSelected];
[self doSearch:searchBar.text inStore:store getPage:1];
[self.searchDisplayController setActive:NO];
}
I tried without the 'setActive:NO' but the self.searchDisplayController.searchTableView remains displayed and I can't se the "underneath" self.tableView with the 'doSearch' results
Ok. Now I have this method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"foundCell";
static NSString *suggestionCellIdentifier = @"suggestionCell";
UITableViewCell *cell;
if (tableView == self.searchDisplayController.searchResultsTableView) {
// HERE I AM WITH SEARCHDISPLAYCONTROLLER
cell = [self.tableView dequeueReusableCellWithIdentifier:suggestionCellIdentifier];
cell.textLabel.text = [self.suggestions objectAtIndex:indexPath.row];
} else {
// HERE I AM WITH SELF.TABLEVIEW
}
return cell;
}
Now it works, but there's a problem! When i tap on the tableview with the results (denoted by self.tableview) I can't catch the tap with the method - (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {...}
but instead I get the re-opening of the uisearchdisplaycontroller in edit mode (so the user can tap inside the searchbar)
Where am I wrong?
fixed! When using displaysSearchBarInNavigationBar = YES we need that the searchbar is OUT for the tableview in the storyboard!