我已经实现了一个 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()
}
最佳答案
将 resultSearchController
的 dimsBackgroundDuringPresentation
设置为 false
resultSearchController.dimsBackgroundDuringPresentation = false
关于ios - 搜索时无法按下 tableView 单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32823435/