views:

36

answers:

2

I currently have a UISearchBar and UIDisplayController defined in my RootViewController as:

- (void)viewDidLoad {
    [super viewDidLoad];

    //Add the search bar
    aSearchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
    [aSearchBar sizeToFit];
    aSearchBar.delegate = self;
    aSearchBar.placeholder = @"Search YouTube...";

    self.tableView.tableHeaderView = aSearchBar;

    searchDC = [[UISearchDisplayController alloc] initWithSearchBar:aSearchBar contentsController:self];

    [self performSelector:@selector(setSearchDisplayController:) withObject:searchDC];

    searchDC.delegate = self;
    searchDC.searchResultsDataSource = self;
    searchDC.searchResultsDelegate = self;

    [aSearchBar release];
    [searchDC release];

}

When the search button is fired, this event is executed to run an API call:

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
    [videoList removeAllObjects];
    if (searchBar.text.length > 0) {
        NSString *searchCriteria = [searchBar.text stringByReplacingOccurrencesOfString:@" " withString:@"+"];

        YTJAppDelegate *appDelegate=(YTJAppDelegate*)[[UIApplication sharedApplication] delegate];
        [appDelegate searchWithCriteria:searchCriteria];

    }       
}

The data is fetched correctly. However. It only becomes visible when I hit the 'Cancel' button on the search.

How can I get the view to update correctly the moment the data source is updated/search button is hit? Is there a special SearchDelegate method I need to implement?

+1  A: 

the code for the associated table view might be helpful, but I am going to guess that you are not calling [self.tableView reloadData] after the search is completed

Aaron Saunders
is there a specific method I should be calling this in?
dpigera
probably after the search is completed
Aaron Saunders
I currently have an 'observer' detect when the Array object has changed to update the tableView.Is there a way to programmaticaly fire the 'Cancel button' event?
dpigera
A: 

turns out the solution was to point the searchDisplayController delegates and data sources at the table view it was implementing:

searchDC.delegate = self;
searchDC.searchResultsDataSource = self.tableView.dataSource;
searchDC.searchResultsDelegate = self.tableView.delegate;
dpigera