搜索时无法按下tableView单元格

时间:2015-09-28 12:49:29

标签: 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

的TableView

 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()
}

1 个答案:

答案 0 :(得分:0)

dimsBackgroundDuringPresentation的{​​{1}}设为false

resultSearchController