Eli*_*hme 5 dictionary uisearchbar ios7
我有一个UISearchBar实现并正常工作.唯一的问题是,如果我在搜索栏中输入字母"e",它将只显示以字母"e"开头的单词,忽略所有开头/有字母"é"的单词.我确保所有关于将数据库加载到NSMutableArray的查询都是正确的UTF-8编码.但问题是,当用户按下"e"时,如何显示"e"和"é"的结果.几乎像所有法语词典一样工作!
这是我在用户按任何字母时过滤单词的方式:
for (Author* author in theauthorsLoadedFinal2)
{
NSRange nameRange = [author.name rangeOfString:text options:NSAnchoredSearch ];
NSRange descriptionRange = [author.genre rangeOfString:text options:NSAnchoredSearch];
if(nameRange.location != NSNotFound || descriptionRange.location != NSNotFound)
{
[filteredTableData addObject:author];
}
}
Run Code Online (Sandbox Code Playgroud)
}
非常感谢
根据 Larme 的提示,答案非常简单!对于以后遇到的所有此问题,请使用以下代码:
NSRange nameRange = [author.name rangeOfString:text options:NSAnchoredSearch | NSDiacriticInsensitiveSearch];
NSRange descriptionRange = [author.genre rangeOfString:text options:NSAnchoredSearch | NSDiacriticInsensitiveSearch];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
87 次 |
| 最近记录: |