我以编程方式创建一个UISearchBar和UISearchdisplayController.视图控制器是一个UITableViewController. @interface StockTableViewController()< UISearchdisplayDelegate,UISearchBarDelegate>你可以看到下面的代码.但是当我在搜索栏中输入时,不会调用shouldReloadTableForSearchString,包括其他UISearchdisplayDelegate方法.
- (void)viewDidLoad { [super viewDidLoad]; self.searchResults = [NSArray array]; UISearchBar *searchBar = [[UISearchBar alloc] init]; searchBar.barStyle = UISearchBarStyleDefault; searchBar.searchBarStyle = UISearchBarStyleDefault; searchBar.showsCancelButton = YES; searchBar.showsScopeBar = NO; searchBar.delegate = self; UISearchdisplayController *searchdisplayController = [[UISearchdisplayController alloc] initWithSearchBar:searchBar contentsController:self]; searchdisplayController.delegate = self; searchdisplayController.searchResultsDataSource = self; searchdisplayController.searchResultsDelegate = self; self.tableView.tableHeaderView = searchBar; } - (void)searchdisplayControllerWillBeginSearch:(UISearchdisplayController *)controller { NSLog(@"searching"); //not showed up in the console } - (BOOL)searchdisplayController:(UISearchdisplayController *)controller shouldReloadTableForSearchString:(Nsstring *)searchString { NSLog(@"%@",searchString); //not showed up in the console nspredicate *predicate = [nspredicate predicateWithFormat:@"name LIKE %@",searchString]; NSArray *results = [Stock MR_findAllSortedBy:@"createdDate" ascending:NO withPredicate:predicate]; if ([results count] > 0) { self.searchResults = results; [self.searchdisplayController.searchResultsTableView reloadData]; } return YES; }
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。