View iPhone UISearchBar not updating immediately?

I currently have a UISearchBar and a 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 triggered, this event is fired to trigger 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];

    }       
}

Data is retrieved correctly. However. This only becomes visible when I click the Cancel button when searching.

How can I get an idea for the correct update at the time of updating the data source or click the search button? Is there a special SearchDelegate method that I need to implement?

+3
source share
2 answers

, , [self.tableView reloadData]

+1

, , searchDisplayController , :

searchDC.delegate = self;
searchDC.searchResultsDataSource = self.tableView.dataSource;
searchDC.searchResultsDelegate = self.tableView.delegate;
+1

Source: https://habr.com/ru/post/1763161/


All Articles