ios - 搜索时无法按下 tableView 单元格

标签 ios swift uitableview uisearchcontroller

我已经实现了一个 searchController,它似乎可以过滤数据,但似乎在我搜索时应用了一种深色覆盖,所以我无法点击单元格?怎么会这样?

ViewDidLoad

        resultSearchController = UISearchController(searchResultsController: nil)
        resultSearchController.hidesNavigationBarDuringPresentation = false


        resultSearchController.delegate = self
        resultSearchController.searchResultsUpdater = self
        resultSearchController.searchBar.sizeToFit()

        resultSearchController.searchBar.backgroundImage = UIImage()
        resultSearchController.searchBar.placeholder = "Søg"
        resultSearchController.searchBar.delegate = self
        resultSearchController.searchBar.returnKeyType = UIReturnKeyType.Default
        resultSearchController.searchBar.delegate = self
        let textFieldInsideSearchBar = resultSearchController.searchBar.valueForKey("searchField") as? UITextField
        textFieldInsideSearchBar?.backgroundColor = UIColor.whiteColor()
        textFieldInsideSearchBar?.clipsToBounds = true
        textFieldInsideSearchBar?.layer.cornerRadius = 1
        textFieldInsideSearchBar?.layer.borderWidth = 2
        textFieldInsideSearchBar?.layer.borderColor = UIColor.whiteColor().CGColor
        textFieldInsideSearchBar?.textColor = UIColor.darkGrayColor()


        self.tableView.tableHeaderView = resultSearchController.searchBar


    definesPresentationContext = true

表格 View

 override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    if (self.resultSearchController.searchBar.text?.characters.count > 0) {
        return self.filteredTableData.count
    }
    else {
        return self.sortedLocations.count
    }
}


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("HomeCell", forIndexPath: indexPath) as! HomeCell

    cell.selectionStyle = UITableViewCellSelectionStyle.None



    if (self.resultSearchController.searchBar.text?.characters.count > 0) {
        cell.backgroundImage.image = UIImage(data: filteredTableData[indexPath.row].image)

        cell.storeNameLabel.text = filteredTableData[indexPath.row].name.uppercaseString
        return cell
    }
    else {
        cell.backgroundImage.image = UIImage(data: sortedLocations[indexPath.row].image)

        cell.storeNameLabel.text = sortedLocations[indexPath.row].name.uppercaseString

        return cell
    }

}


func updateSearchResultsForSearchController(searchController: UISearchController)
{


    filteredTableData = sortedLocations.filter {
        $0.name.localizedCaseInsensitiveContainsString(searchController.searchBar.text!)

    }

    self.tableView.reloadData()
}

最佳答案

resultSearchControllerdimsBackgroundDuringPresentation 设置为 false

resultSearchController.dimsBackgroundDuringPresentation = false

关于ios - 搜索时无法按下 tableView 单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32823435/

相关文章:

iOS - UITableViewCell 的隐藏 UIImageView 是否应该在可见之前没有分配的图像?

ios - 创建后 UITableViewCell 的顺序不正确

swift - TableView 从顶部确定第三个单元格

ios - (iOS 6) 从 UIActivityViewController 外部使用 UIActivity 的自定义子类

ios - 什么 iOS 版本支持 NSTimer 有效属性?

iphone - UINavigationTransitionView、UILayoutContainerView和UIViewControllerWrapperView的作用是什么

Swift PageControl 当前页面上较大的点

ios - header 未定义 responseJSON Alamofire 2.0 和 Swift 2.0

ios - 在表格 View 单元格中加载和缓存多个 UIImageView 不起作用

ios - 禁用 UIPageViewController 反弹