ios - 推送 View Controller 时,UISearchController searchBar 不会消失

标签 ios objective-c uitableview uisearchbar uisearchcontroller

我在 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/

相关文章:

ios - Post方法请求Alamofire(responseObject)

ios - 我可以为 UIButton 传递带有 @selector 的数组参数吗?

objective-c - .lproj 和 Localizable.strings : project with localized text?

ios - 在 UITableViewController 中为多个实例初始化结构的位置

javascript - 在 JavaScript 中,是否可以检测 Android 和 iOS 浏览器中的屏幕何时关闭

ios - UIMenuController 未在 UICollectionViewController 子类上显示自定义操作

iphone - 为宏使用未声明的标识符

objective-c - 使用 NSOperation 出奇地慢

ios - 在编辑模式下设置 allowsMultipleSelectionDuringEditing 时未在 UITableView 中选择单元格

ios - 由于UITapGestureRecognizer无法调用didSelectRowAtIndexPath