iOS 11中的SearchController无法触及任何tableView单元格

Pio*_*icz 2 objective-c uitableview ios uisearchcontroller

搜索控制器的系统行为:

  • 转到iPhone设置
  • 滑动以显示searchBar
  • 点按searchBar
  • TableView现在有灰色,如果我触摸任何地方(不在searchBar中),searchBar将隐藏
  • 我输入任何文本,tableView现在有正常颜色,我可以点击进入任何搜索过的单元格.

在我的应用程序中,点击任何文本后,tableView仍然是灰色的.我无法点击任何搜索过的单元格.不同之处在于,当我搜索时,我使用updateSearchResultsForSearchController和reloadData 更新旧的tableView(搜索后我没有不同的tableView).

问题是如何在searchcontroller中输入任何文本后隐藏这个灰色视图并有机会点击单元格?

我创建搜索控制器的方式:

UISearchController * search = [[UISearchController alloc] initWithSearchResultsController:nil];
search.searchResultsUpdater = self;
self.navigationItem.searchController = search;
self.navigationItem.hidesSearchBarWhenScrolling = YES;
self.navigationItem.searchController.searchBar.barTintColor = [UIColor blueColor];
self.navigationItem.searchController.searchBar.delegate = self;
Run Code Online (Sandbox Code Playgroud)

以及我如何更新tableView单元格:

- (void)updateSearchResultsForSearchController:(UISearchController *)searchController {
    self.actualSearchController = searchController;
    self.filteredData = [self filterContentForSearchText:searchController.searchBar.text];
    [self.tableView reloadData];
}

- (NSMutableArray<MySectionContainter *> *)filterContentForSearchText:(NSString *)text {
    NSMutableArray<MySectionContainter *> *sections = [NSMutableArray array];

    for (MySectionContainter *section in self.tableData) {
        NSArray *objects = [sectionInfo.rowObjects filteredArrayUsingPredicate:[self.filterSource predicateForSearching:text]];

        if ([objects count] > 0) {
            [sections addObject:[[MySectionContainter alloc] initWithTitle:section.title andObjects:objects]];
        }
    }

    return sections;
}

- (NSPredicate *)predicateForSearching:(NSString *)text {
    return [NSPredicate predicateWithBlock:^BOOL(id  _Nullable evaluatedObject, NSDictionary<NSString *,id> * _Nullable bindings) {
        if ([evaluatedObject isKindOfClass:[MyClass class]]) {
            return [((MyClass *)evaluatedObject).title containsString:text];
        }


    return NO;
    }];
}
Run Code Online (Sandbox Code Playgroud)

示例项目代码:https://pastebin.com/m9V2dunB

截图:

在此输入图像描述

系统行为:

在此输入图像描述

测试项目:https: //www.sendspace.com/file/2lhedj

tru*_*duc 6

我通过添加此行来解决您的演示项目中的问题 viewDidLoad

search.dimsBackgroundDuringPresentation = NO;

只需删除昏暗的背景UISearchController,一切都会正常工作.