【发布时间】:2012-09-28 06:08:44
【问题描述】:
我正在我的 iPhone 应用程序上进行搜索屏幕(搜索姓名列表),我需要同时按名字和姓氏进行搜索。
假设我的搜索表视图包含如下名称
Ravi Kiran
sujay huilgol
harry potter
我的搜索只对名字起作用,即如果我搜索 Ra 它会显示 Ravi Kiran 但是当我搜索 Kiran 时不显示 Ravi Kiran。
我的filterContentForSearchText是这样的:
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
[self.arrSearhResults removeAllObjects]; // First clear the filtered array.
// Search the main list for Usernames whose type matches searchText; add items that match to the filtered array.
for(NSString * strUserName in arrUserInfo )
{
NSComparisonResult result = [strUserName compare:searchText options:(NSLiteralSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])];
if (result == NSOrderedSame)
{
// Update the filtered array based on the search text and scope.
[self.arrSearhResults addObject:strUserName];
//NSLog(@"arrSearhResults %@",arrSearhResults);
}
}
}
我可以尝试什么来解决这个问题?
【问题讨论】:
-
NSOrderedSame 如果接收者的子字符串和 aString 在词法值上是等价的。
标签: iphone objective-c ios search uisearchdisplaycontroller