updateSearchResultsForSearchController未被调用

时间:2017-05-31 08:20:10

标签: ios objective-c

我的viewcontroller .h如下

cd <MyApp>/include

mkdir -p MacOSX/Qt/headers

cd MacOSX/Qt/headers

QT_CORE_HEADERS=<your Qt path up to verson subdirectory>/clang_64/lib/QtCore.framework/Versions/5/Headers

ln -s  $QT_CORE_HEADERS QtCore

Delete existing Makefile `rm -f <MyApp>/Build/Makefile`

我的viewcontroller.m如下

@interface DiaryViewController : BaseViewController<UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate,UISearchControllerDelegate,UISearchResultsUpdating>

我正在尝试在包含tableview的视图控制器中实现搜索功能。我发现尽管在viewDidLoad上有适当的声明,但- (void)viewDidLoad { [super viewDidLoad]; //for search self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil]; self.searchController.searchResultsUpdater = self; self.searchController.delegate = self; self.searchController.searchBar.delegate = self; // // self.tableView.tableHeaderView = self.searchController.searchBar; self.definesPresentationContext = YES; } - (void)updateSearchResultsForSearchController:(UISearchController *)searchController { NSString *searchString = searchController.searchBar.text; [self searchForText:searchString scope:searchController.searchBar.selectedScopeButtonIndex]; [self.tableView reloadData]; } -(void)searchForText:(NSString*)searchText scope:(NSInteger)scope { NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"diaryText like %@", searchText]; self.searchResults = [self.diaryInfoArray filteredArrayUsingPredicate:resultPredicate]; // you forget to reload Data //[self.tableView reloadData]; // else use //[yourtableView reloadData]; } 没有被调用。任何解决方案都将不胜感激。

0 个答案:

没有答案