【问题标题】:UISearchController in UITabBarController is not responding to touchUITabBarController 中的 UISearchController 没有响应触摸
【发布时间】:2015-08-18 18:12:45
【问题描述】:

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

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];

【问题讨论】:

    标签: ios iphone uitableview ipad uisearchcontroller


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2011-04-24
      • 1970-01-01
      • 2013-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-19
      • 2016-11-13
      相关资源
      最近更新 更多