4

shouldReloadTableForSearchString メソッドが NO を返しても、UISearchDisplayController に「結果がありません」と表示されるのはなぜですか? 何もせずに黒のままでいいのではないですか?そうならないようにするにはどうすればよいですか?

#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

1 に答える 1

0

いいえ、tableView (searchTableViewによって作成されたものを含むUISearchDisplayController) は、表示時に自動的にデータを読み込みます。このshouldReloadTableForSearchString:メソッドは、文字が検索ボックスに入力されたときにのみテーブルが再ロードされるのを防ぎます。

UISearchDisplayContollerに対する私の回答を参照してください–これに対処する方法の提案については、検索バーに入力する際に​​テーブルのリロードを防ぐことができません。

于 2011-04-06T21:19:49.360 に答える