UISearchDisplayController
我在我的 iphone 应用程序屏幕之一中使用。我需要UISearchDisplayController
在 uisearchbar 中仅查看用户类型,它将加载 searchtableview 并显示数据。现在我的问题是一切都在进行,但是当我尝试选择行时搜索 tabelview 我的-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
代表没有触发,因此 searchtableview 在它之后永远不会隐藏,直到我点击 search-bar 的取消按钮。当我尝试点击 searchtabelview 的行时,我的搜索栏隐藏了,只有 serachtableview 没有隐藏,没有任何事情发生-选择删除方法。
我已经做了以下事情。所以谁能告诉我我的错误是什么。
注意:我在屏幕中没有任何其他表格视图。只是搜索显示控制器的 uisearchtableview(这会导致问题吗?)
self.searhController = [[UISearchDisplayController alloc]
initWithSearchBar:self.searchBar
contentsController:self];
self.searhController.delegate=self;
self.searhController.searchResultsDataSource = self;
self.searhController.searchResultsDelegate = self;
self.edgesForExtendedLayout = UIRectEdgeNone;
[self.searhController setDelegate:self];
[self.searhController setSearchResultsDelegate:self];
[self.searhController setSearchResultsDelegate:self];
#pragma mark TableView Delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView== self.searhController.searchResultsTableView) {
if(self.searchResults.count<=0)
return 0;
else
return self.searchResults.count;
}
else{
return 0; }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
tableView.delegate=self;
tableView.dataSource=self;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if(tableView==self.searhController.searchResultsTableView){
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
City *cityObj=[self.searchResults objectAtIndex:indexPath.row];
cell.textLabel.text = cityObj.name;
}
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (tableView==self.searhController.searchResultsTableView) {
[self.searhController setActive:NO animated:YES];
[self.searchDisplayController setActive:NO animated:YES];
[self.searhController setActive:NO animated:NO];
}
}
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString{
if ([[searchString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length])
self.tvSearchView = self.searhController.searchResultsTableView;
else
self.tvSearchView = controller.searchResultsTableView;
if(searchString.length>=3){
[self getCityList:searchString];
return YES;
}
else{
return NO;
}
}