1
私はiPhoneの連絡先検索バーのように振る舞うはずの検索バーを作成しています。 は、ここに私のコードですiPhone連絡先アプリとして検索バーを作る方法や複数の不完全なキーワードを扱う検索バー
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
NSRange whiteSpaceRange = [result rangeOfCharacterFromSet:[NSCharacterSet whitespaceCharacterSet]];
if (whiteSpaceRange.location != NSNotFound)
{
NSString * stringAfterSpace = [result substringFromIndex:whiteSpaceRange.location];
NSString * stringBeforeSpace= [result substringToIndex:whiteSpaceRange.location];
NSPredicate *predicateForAfterSpace=[NSPredicate predicateWithFormat:@"catNm CONTAINS[cd] %@",stringAfterSpace];
NSPredicate *predicateForBegining = [NSPredicate predicateWithFormat:@"catNm BEGINSWITH[cd] %@", stringBeforeSpace];
NSPredicate *compoundPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[predicateForBegining, predicateForAfterSpace]];
searchArray = [[dataArray filteredArrayUsingPredicate:compoundPredicate] mutableCopy];
}
else
{
NSPredicate *predicateForBegining = [NSPredicate predicateWithFormat:@"catNm BEGINSWITH[cd] %@", result];
NSString *stringAfterSpace=[NSString stringWithFormat:@" %@",result];
NSPredicate *predicateForAfterSpace=[NSPredicate predicateWithFormat:@"catNm CONTAINS[cd] %@",stringAfterSpace];
NSPredicate *compoundPredicate = [NSCompoundPredicate orPredicateWithSubpredicates:@[predicateForBegining,predicateForAfterSpace]];
searchArray = [[dataArray filteredArrayUsingPredicate:compoundPredicate] mutableCopy];
}
}
主な違いは、私の検索バーが1つの不完全なキーワードを処理しますが、ある以上、one.suppose array={{[email protected]"Asus Zenfone 3 Max"},{[email protected]"Asus Zenfone Go}}
私はasus zen max
の検索が、それがうまくいかない場合asu zen
またはzen ma
が、それは結果を示しているが、検索した場合 私が知りたいのは、searchBarで複数のスペースを扱う方法です。