UISearch栏不区分大小写?
在表视图中,我设置了 UISearchBar、设置委托并添加协议。
当用户点击一个单词时,一切正常,除了“网球”的搜索与“网球”不同。
如何使搜索栏成为不区分大小写的 UISearchBar?这是我的代码,我认为所有事情都会发生:
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
[tableData removeAllObjects];// remove all data that belongs to previous search
if([searchText isEqualToString:@""]||searchText==nil){
[myTableView reloadData];
return;
}
NSInteger counter = 0;
for(NSString *name in dataSource)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
NSRange r = [name rangeOfString:searchText];
if(r.location != NSNotFound)
[tableData addObject:name];
counter++;
[pool release];
}
[myTableView reloadData];
}
In a table view I have set a UISearchBar, set the delegate, and add the protocol.
When user tap a word everything is okay except that the search of "tennis" is different from "Tennis".
How can I make the search bar a case-insensitive UISearchBar? Here is my code where I think evrything happens:
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
[tableData removeAllObjects];// remove all data that belongs to previous search
if([searchText isEqualToString:@""]||searchText==nil){
[myTableView reloadData];
return;
}
NSInteger counter = 0;
for(NSString *name in dataSource)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
NSRange r = [name rangeOfString:searchText];
if(r.location != NSNotFound)
[tableData addObject:name];
counter++;
[pool release];
}
[myTableView reloadData];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
最简单的方法可能是
The easiest way to do this is probably
试试这个。
Try this.
当您进行比较时,请尝试使用小写版本进行比较。
只是为了澄清,这不会更改任何值,只是返回原始值的小写版本,然后用它来进行比较,
When you do the comparison, try doing it with the lowercase version.
Just to clarify, this will not change any of the values, just return a lowercase version of the original, that you then use to do the comparison with,
有一些“lowercaseString”函数,不知道我在哪里遇到这个,因为我与iPhone无关,我相信如果你用谷歌搜索你会找到一些东西。
Theres some 'lowercaseString' function, don't know where I came across this seeing as I have nothing to do with iPhones, I'm sure if you google it you'll find something.