在UISearchBar中过滤撇号特殊字符-Swift,Xcode

问题描述

我目前有一个运行良好的UISearchBar,但是,我注意到在searchBar中输入撇号时不会返回任何结果。 例如::如果我有一个字符串: Bob's ,如果我搜索 Bob ,它将返回所说的字符串,但是,当我在其中输入撇号时searchBar: Bob' searchBar不返回结果。

我在网上搜索解决方案,但是没有找到任何可行的方法。任何答复将不胜感激,谢谢。

UISearchBar代码

    func searchBar(_ searchBar: UISearchBar,textDidChange searchText: String) {
    if searchText.isEmpty {
        filteredData = data
    } else {
        filteredData = data.filter{$0.title.range(of: searchText,options: .caseInsensitive) != nil }
    }
    self.tableView.reloadData()
}

}

结构:

struct Category {
    let title: String

    let items: [String]
}

数组: Category(title: "Bob's ",items: ["Data: xxx","Data: xxx",]),

cellForRowAt函数

    func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCell(withIdentifier: "cell",for: indexPath) as! MyTableViewCell

        let title = filteredData[indexPath.row].title

          cell.myLabel.text = title

          cell.myImg.image = UIImage(named: title + ".png")

          return cell

    }

}

在searchBar中输入撇号时,在控制台中返回的输出 filteredData = []

解决方法

此问题已解决。事实证明存在撇号的变体。 U + 0027(')和U + 2019(’)。 U + 2019(’)是iPhone上的默认撇号,可与上面的UISearchBar代码一起使用。希望这对与我有同样问题的人有所帮助。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...