我在 ma UIViewcontroller
中使用 UISearchController,其中包含一个 UITableView
,我在 viewDidLoad
中执行此操作:
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.delegate = self;
self.searchController.searchResultsUpdater = self;
self.searchController.searchBar.delegate = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.definesPresentationContext = NO;
当我按下导航栏中的按钮时,我会这样做:
self.tableView.contentOffset = CGPointMake(0, 0 - self.tableView.contentInset.top);
self.tableView.tableHeaderView = self.searchController.searchBar;
[self.searchController.searchBar becomeFirstResponder];
一切正常,但是当我从 UITableView
中的一行中推送 UIViewController
结果时,UISearchBar
留在那里并显示在另一个 View 的内容,我如何在推送 View 时关闭并在返回查看 UITableView
的结果时呈现?
谢谢
编辑:
这是didSelectRowAtIndexPath
方法的代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
DetailListController *detailList = [[DetailListController alloc] init];
[self.navigationController pushViewController:detailList animated:YES];
}
最佳答案
将此代码放入您的viewDidLoad
:
self.definesPresentationContext = YES;
关于ios - 推送 View Controller 时,UISearchController searchBar 不会消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32974723/