views:

38

answers:

3

I have implemented a UITableView with search bar (and search display) - all works fine, but the table results do not get updated until the search bar cancel button is tapped.

Delegate methods:

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
    // asynchronous request with [self.tableView reloadData] in the connectionDidFinishLoading
    [self getProductData:searchBar.text]; 
 [searchBar resignFirstResponder];
 [self.tableView reloadData];


}

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {

}

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {

}

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {

}

- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar  {  
} 

- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar {
 return YES;
}

Do I need to call a delegate method after receiving the data from the server? Or should I make the request synchronous?

Thanks


edit: I tried with a synchronous request and it still does not work!

A: 

I think you have to implement:

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString

and return YES

See the TableSearch sample code

Benoît
Thanks - I've already tried that, but it still does not work. I also included - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption
KSoza
I have used this example to implement my search bar, and its works fine...
Benoît
Hummm, I used UISearchDisplayController, not UISearchBarDelegate
Benoît
A: 

Please try something like this:

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
    [self getProductData:searchText]; 
    [self.tableView reloadData];
}
vikingosegundo
Hi, I've tried this and this causes the HTTP request to be called every time text in the search bar changes - in my case this causes the app to crash.
KSoza
In that case u should consider to change the design of ur app.
vikingosegundo