0

我正在使用 Three20 框架,并且自动搜索功能使搜索非常缓慢,我想禁用自动搜索并在用户单击键盘上的“搜索”按钮后触发搜索。

有什么办法可以禁用自动搜索?非常感谢

4

1 回答 1

0

在 中创建一个XXSearchDisplayController派生自TTSearchDisplayController的新显示控制器XXSearchDisplayController.m

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller    
 shouldReloadTableForSearchString:(NSString *)searchString {
return NO;
}

这将禁用自动搜索。在此之后,去你的类派生自TTTableViewController,说XXProductsTableViewController

@implementation XXProductsTableViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        UISearchBar* searchBar = [[UISearchBar alloc] init];
        searchBar.delegate = self;
        _searchController = [[XXSearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
    }
    return self;
}

#pragama mark - UISearchBarDelegate
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
    [self.searchViewController.dataSource search:searchBar.text];
}
@end

一旦用户点击“搜索”按钮,上面的代码就会进行搜索

于 2012-06-07T15:00:33.870 回答