开发者

UISearchDisplayController "shouldReloadTableForSearchString return NO" reloads table

开发者 https://www.devze.com 2022-12-28 19:58 出处:网络
Why does my UISearchDisplayController show \"No results\" even if the shouldReloadTableForSearchString method returns NO? Shouldn\'t it just do nothing and stay black? How can I prevent it from doing

Why does my UISearchDisplayController show "No results" even if the shouldReloadTableForSearchString method returns NO? Shouldn't it just do nothing and stay black? How can I prevent it from doing so?

#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:(UISearchDisplay开发者_JAVA技巧Controller *)controller shouldReloadTableForSearchString:(NSString *)searchString {
    return NO;
}


- (void)dealloc {
    [super dealloc];
}


@end


No, tableViews (including the searchTableView created by a UISearchDisplayController) automatically load data when they are displayed. The shouldReloadTableForSearchString: method will prevent the table from reloading only as characters are typed into the search box.

See my answer to UISearchDisplayContoller – can't prevent table reload on typing in search bar for suggestions on how to deal with this.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号