ios - UITabBarController 中的 UISearchController 不响应触摸

标签 ios iphone uitableview ipad uisearchcontroller

我有一个 tabbarcontroller,它位于 uinavigationcontroller 内部,我试图在其中一个选项卡的 tableviewheader 中放置一个搜索栏。我能够在导航 Controller 上的任何屏幕上成功使用下面的代码,但当 View 位于选项卡 Controller 上时,搜索不会响应触摸。我可以在代码中成功将其设置为事件状态,但我也需要触摸才能工作。

self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchBar.scopeButtonTitles = @[@"SEARCH"];
[self.searchController.searchBar setPlaceholder:@"SEARCH"];
self.searchController.searchBar.delegate = self;
self.searchController.delegate = self;
self.searchController.searchBar.backgroundColor = [UIColor colorWithRed:0.843 green:0.843 blue:0.843 alpha:1];
self.searchController.searchBar.tintColor = [UIColor blackColor];
self.myTableView.tableHeaderView = self.searchController.searchBar;
self.definesPresentationContext = YES;
[self.searchController.searchBar sizeToFit];

最佳答案

我遇到了类似的问题,并发现 self.definesPresentationContext = YES; 行是问题的根本原因(有关更多信息: UISearchController and definesPresentationContext )。

确保类设置 self.definesPresentationContext = YES; 也是搜索栏的父 View Controller 。如果您使用提供的代码初始化 UISearchController,然后将搜索栏分配给层次结构外部的 View ,这可能会导致问题。

关于ios - UITabBarController 中的 UISearchController 不响应触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32079761/

相关文章:

ios - 在 UITableView 中滚动时移动 View

iphone - 如何更改突出显示状态下的 UITableViewCell 文本颜色?

ios - 自动布局 View 在不同的屏幕尺寸上总是相同的尺寸

ios - 如何在 Swift3 中使用分隔符连接 NSMutableArray 的对象

iphone - 我可以在 UITextView 中添加换行符和 HTML 链接吗?

.net - 设计在多个移动平台上消费的服务

ios - TableView 重新加载未从 Backendless 正确更新

iOS >> ShareKit >> 推特设置 : How to Get the "bit.ly" Data?

ios - 使用 AWS Comprehend iOS 的问题

ios - 搜索结果 TableView 未被选中