Uitableview UISearchController显示不正确
我最近使用了一个教程,非常好用,非常容易理解。我的问题是,这只允许您搜索文本。与我的textViewCells一样,我还有Uitableview UISearchController显示不正确,uitableview,swift,nspredicate,uisearchcontroller,Uitableview,Swift,Nspredicate,Uisearchcontroller,我最近使用了一个教程,非常好用,非常容易理解。我的问题是,这只允许您搜索文本。与我的textViewCells一样,我还有detailTextLabel和一个accessoryView图像。一旦输入了文本,我想成为搜索单元的一部分。此时,tableViewCell中元素0处的任何内容都与名称分开。用于更改和更新搜索控制器的代码: func updateSearchResultsForSearchController(searchController: UISearchController){
detailTextLabel
和一个accessoryView
图像。一旦输入了文本,我想成为搜索单元的一部分。此时,tableViewCell中元素0处的任何内容都与名称分开。用于更改和更新搜索控制器的代码:
func updateSearchResultsForSearchController(searchController: UISearchController){
filteredMatchesNames.removeAll(keepCapacity: false)
let searchPredicate = NSPredicate(format: "SELF CONTAINS[c] %@", searchController.searchBar.text)
let arrayName = (finalMatchesName as NSArray).filteredArrayUsingPredicate(searchPredicate)
filteredMatchesNames = arrayName as! [String]
self.tableView.reloadData()
}
对于表格视图
单元格行索引路径
:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell
var imageView = UIImageView(frame: CGRectMake(cell.frame.origin.x + cell.frame.width - cell.frame.height - 5, 5, cell.frame.height - 10, cell.frame.height - 10))
if (self.resultSearchController.active) {
var dis = ["2222", "4444"]
var images = UIImage(data: finalMatchesImage[indexPath.row])
imageView.image = images
cell.textLabel?.text = filteredMatchesNames[indexPath.row] //This works fine
cell.detailTextLabel?.text = dis[indexPath.row] //this doesn't work
cell.accessoryView = imageView //This doesn't work
return cell
}
else {
var images = UIImage(data: finalMatchesImage[indexPath.row])
imageView.image = images
var dis = ["2222", "444"]
cell.textLabel?.text = finalMatchesName[indexPath.row] //This works fine
cell.detailTextLabel?.text = dis //This works fine
cell.accessoryView = imageView //This works fine
return cell
}
}
完整的代码在链接中,尽管我认为问题应该在
cellforrowatinexpath
中,如果我可以这样做的话,那么搜索整个单元格而不仅仅是文本。您可以创建一个NSDictionary
,其格式如下(在伪代码中){{keyRow1:{text:text1,detailsText1},{keyRow2:{text:text2,details:detailsText2}}
,并使用谓词(SELF.text包含[c]@或SELF.details包含[c]@,textToSearch,textToSearch)
。谢谢,你能把这句话写进更多的答案中,让我能更好地理解吗?