【问题标题】:UISearchDisplayController "shouldReloadTableForSearchString return NO" reloads tableUISearchDisplayController "shouldReloadTableForSearchString return NO" 重新加载表
【发布时间】:2014-01-07 00:40:23
【问题描述】:

即使 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

【问题讨论】:

标签: iphone uisearchdisplaycontroller


【解决方案1】:

不,tableViews(包括由UISearchDisplayController 创建的searchTableView)在显示时会自动加载数据。 shouldReloadTableForSearchString: 方法将防止表格仅在输入字符时重新加载到搜索框中。

请参阅我对UISearchDisplayContoller – can't prevent table reload on typing in search bar 的回答,了解如何处理此问题的建议。

【讨论】:

    猜你喜欢
    • 2011-04-08
    • 2013-08-21
    • 1970-01-01
    • 1970-01-01
    • 2021-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多