0
아래 제품을 검색하고 있습니다. 그것은 잘 작동하지만 2 단어 사이를 검색 할 때 사용자가 다음 단어의 첫 번째 문자를 입력하면 결과가 사라집니다. 즉 "td pro"또는 "pro td"를 검색하면 결과가 나타납니다. 이처럼 검색하면 td (결과가 있음) td (공백) 결과가 없습니다 (결과가 있습니다). 사용자가 제품을 검색 할 수 없기 때문에 componentsSeperatedByString에서 단어를 공백으로 구분해야합니다. 어떤 특정 순서로. 더 좋은 방법이 없다면?디스플레이 컨트롤러 검색 iOS 결과가 사라지고 단어 사이에 다시 나타납니다.
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
[self.filteredListContent removeAllObjects]; // First clear the filtered array.
for (XMLStringFile *new in rssOutputData_MutableArray)
{
//Product scope
if ([scope isEqualToString:@"Product"])
{
// Split into search text into separate "words"
NSArray * searchComponents = [searchText componentsSeparatedByString: @" "];
;
BOOL foundSearchText = YES;
// Check each word to see if it was found
for (NSString * searchComponent in searchComponents) {
NSRange result = [new.xmlItem rangeOfString:searchComponent options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch)];
NSRange descriptionRange = [new.xmlDescription rangeOfString:searchComponent options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch)];
foundSearchText &= (result.location != NSNotFound|| descriptionRange.location != NSNotFound);
}
// If all search words found, add to the array
if (foundSearchText)
{
[self.filteredListContent addObject: new];
}
}
}
}
많은 감사