gpt4 book ai didi

iphone - 如何同时按名字和姓氏搜索

转载 作者:行者123 更新时间:2023-11-29 11:08:35 25 4
gpt4 key购买 nike

我正在我的 iPhone 应用程序上执行搜索屏幕(搜索姓名列表),我需要在其中按名字和姓氏进行搜索。

假设我的搜索 TableView 包含如下名称

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);
}
}

}

我可以尝试如何解决这个问题?

最佳答案

使用rangeOfString搜索整个字符串

 for(NSString * strUserName in arrUserInfo )
{
NSRange range = [strUserName rangeOfString:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch)];
if (range.length > 0)
{
[self.arrSearhResults addObject:strUserName];
}
}

关于iphone - 如何同时按名字和姓氏搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12634493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com