本文介绍了UISearch酒吧不区分大小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在表格视图中,我设置了一个UISearchBar,设置了委托,并添加了协议。
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".
如何使搜索栏成为不区分大小写的UISearchBar?这是我的代码,我认为发生了这样的事情:
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];
}
推荐答案
最简单的方法可能
NSRange r = [name rangeOfString:searchText options:NSCaseInsensitiveSearch];
这篇关于UISearch酒吧不区分大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!