我在ViewDidLoad
//create the search controller
self.searchController = [[UISearchController alloc]initWithSearchResultsController:nil];
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchResultsUpdater = self;
self.searchController.delegate = self;
self.definesPresentationContext = YES;
[self.searchBarHolder addSubview: self.searchController.searchBar];
self.searchController.searchBar.delegate = self;
当用户点击CANCEL
按钮时,将调用以下委托方法。
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
self.searchController.active = NO;
self.myTableView.hidden = YES;
self.transparentViewSearch.hidden = YES;
}
第self.searchController.active=NO
行将用户导航回上一个视图控制器。
此外,self.transparentViewSearch.hidden = YES
行无效。视图仍然可见。
发生了什么事?
答案 0 :(得分:0)
you are using same table for showing search result
self.searchController = [[UISearchController alloc]initWithSearchResultsController:nil];
取消搜索结果后,您需要更新表格。
[self.tableview reloadData];
然后你需要做类似下面的事情。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(bShowSearchResult)
{
// return search result count
}
else
{
// return normal list count
}
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(bShowSearchResult)
{
// create cell using search result data
Data = [lstSearchResults objectAtIndex:indexPath.row];
//create cell
// return cell
}
else
{
Data = [lstFiles objectAtIndex:indexPath.row];
//create cell
// return cell
}
}
我认为这会对你有所帮助