UISearchDisplayController "shouldReloadTableForSearchString returns NO" reload table

Why does my UISearchDisplayController show "No Results" even if the shouldReloadTableForSearchString method returns NO? Shouldn't he do nothing and stay black? How can I prevent this?

#import "RootViewController.h" @implementation RootViewController #pragma mark Table view methods - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } // Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (tableView == self.searchDisplayController.searchResultsTableView) { return 0; } return 10; } // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } // Configure the cell. cell.textLabel.text = [NSString stringWithFormat:@"row %d", indexPath.row]; return cell; } #pragma mark SearchController stuff - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { return NO; } - (void)dealloc { [super dealloc]; } @end 
+4
source share
1 answer

No, tableViews (including the searchTableView created by UISearchDisplayController ) automatically load data when it is displayed. The shouldReloadTableForSearchString: method shouldReloadTableForSearchString: prevent the table from reloading only as characters are entered in the search field.

See my answer UISearchDisplayContoller - cannot prevent the table from reloading when entering in the search bar for suggestions on how to handle this.

0
source

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


All Articles