搜索控制器的系统行为:

  • 转到iPhone设置
  • 滑动以显示搜索栏
  • 点击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;
    

    以及如何更新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;
        }];
    }
    

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

    屏幕截图:

    ios - iOS 11中的SearchController。无法触摸任何tableView单元格-LMLPHP

    系统行为:

    ios - iOS 11中的SearchController。无法触摸任何tableView单元格-LMLPHP

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

    最佳答案

    我通过将这一行添加到viewDidLoad中来解决您的演示项目中的问题
    search.dimsBackgroundDuringPresentation = NO;
    只需删除UISearchController的暗淡背景,一切都会正常。

    关于ios - iOS 11中的SearchController。无法触摸任何tableView单元格,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47072408/

    10-14 23:35
    查看更多