简体   繁体   English

搜索时,UITableview不会重新加载

[英]UITableview doesn't reload when searching

I'm having a UISearchbar in my navigationbar. 我的导航栏中有一个UISearchbar。 When I search something the delegate: 当我搜索委托时:

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
    NSLog(@"Should reload");
    [self filterContentForSearchText:searchString
                               scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
                                      objectAtIndex:[self.searchDisplayController.searchBar
                                                     selectedScopeButtonIndex]]];

    return YES;
}

is called so It should reload my tableview. 被调用,所以它应该重新加载我的tableview。 But it doesn't. 但事实并非如此。 I've got two results in my search array so that's not the problem. 我的搜索数组中有两个结果,所以这不是问题。

My init in my UITableviewController is like this: 我在UITableviewController中的初始化是这样的:

_searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
_searchBar.delegate = self;

_searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:_searchBar contentsController:self];
_searchDisplayController.delegate = self;
_searchDisplayController.searchResultsDataSource = self;
_searchDisplayController.searchResultsTableView.delegate = self;

After I alloc init my UITableviewController I do this: 在分配初始化我的UITableviewController之后,我这样做:

_poiTableView = [[POITableViewController alloc] init];
self.navigationItem.titleView = _poiTableView.searchBar;

so the searchbar is in my navigationbar and it calls searchdislaycontroller the only thing is that it doesn't reload my tableview. 因此搜索栏位于我的导航栏中,它调用searchdislaycontroller唯一的事情是它不会重新加载我的表视图。 Before I moved the searchbar to the navigationbar, it was in the headercell of the tableview. 在将搜索栏移动到导航栏之前,它位于表视图的标题单元中。 Then it reloaded my tableview. 然后,它重新加载了我的tableview。 I only moved the searchbar tot the navigationbar. 我只将搜索栏移动到了导航栏。

Implement the method searchBarShouldEndEditing: and there reload the tableview with [tableView reloadData]; 实现方法searchBarShouldEndEditing:并使用[tableView reloadData];重新加载tableview [tableView reloadData];

Also, return YES at the end of the method since the return type is BOOL. 另外,由于返回类型为BOOL,因此在方法末尾返回YES。 Otherwise, it won't receive the end editing delegate calls. 否则,它将不会收到结束编辑委托调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM