UISearchDisplayController
에 문제가있어서 검색이 제대로 작동하지 않습니다.두 번째 히트 후 검색 방법이 작동하지 않습니다.
이 내 코드입니다 :
- (void)filterContentForSearchText:(NSString*)searchText
scope:(NSString*)scope
{
[self.searchResults removeAllObjects];
for (int i = 0; i < [temp_category count]; i++) {
BOOL foundResult = FALSE;
if ([[temp_category objectAtIndex:i] rangeOfString:searchText].location != NSNotFound) {
foundResult = TRUE;
}
if ([[price_producttitle objectAtIndex:i] rangeOfString:searchText].location != NSNotFound) {
foundResult = TRUE;
}
if ([[price_type objectAtIndex:i] rangeOfString:searchText].location != NSNotFound) {
foundResult = TRUE;
}
if ([[price_description objectAtIndex:i] rangeOfString:searchText].location != NSNotFound) {
foundResult = TRUE;
}
if (foundResult) {
NSNumber *result = [NSNumber numberWithInt:i];
if ([self searchResults] == nil) {
NSMutableArray *array = [[NSMutableArray alloc] init];
[self setSearchResults:array];
[array release];
}
[searchResults addObject:result];
}
}
NSLog (@"array = %i", [searchResults count]);
NSLog(@"%@",searchResults);
}
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller
shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString
scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
objectAtIndex:[self.searchDisplayController.searchBar
selectedScopeButtonIndex]]];
return YES;
}
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller
shouldReloadTableForSearchScope:(NSInteger)searchOption
{
[self filterContentForSearchText:[self.searchDisplayController.searchBar text]
scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
objectAtIndex:searchOption]];
return YES;
}
하지만 첫 글자와 검색, 올바른 안타를 제공 시작할 때 때문에 나는 아직도 혼동하고있다. 그러나 두 번째 문자를 입력하면 하나의 결과 만 표시됩니다 (데이터 샘플에서 알 수있는 한 더 많은 부분이있는 반면). 나는 뭔가 잘못하고있다. 사용자가 텍스트를 입력 할 때와 관련이 있다고 생각하지만 어떤 방법을 사용해야하는지 혼란 스럽습니다. this 튜토리얼 및 this SO 질문 :
내가 지금 가지고있는 코드의 조합입니다.
누군가 좋은 방향으로 나에게 힌트를 줄 수 있습니까? 결과를 표시하는 것은 좋지만이 부분 만 나를 귀찮게합니다. 나는 그것이 방법을 해고하는 것과 관련이 있다고 생각한다. [self.searchResults removeAllObjects];
.
사용하여 수동으로 해주세요 UISearchDisplayController로 중단하고 UISearchBar를 별도로 구현했으며 모든 것이 지금 작동 중입니다. – Prastow
차가워졌습니다. 당신이 할 수있을 때 (나는이 일을하는 데 약간의 시간 제한이 있음을 알고 있습니다), 당신은 미래의 사이트 방문자가 가질 수있는 유사한 질문에 대한 해결책을 찾을 수 있도록 아래 답변으로 게시 할 수 있습니까? 감사. – pasawaya
나는 대답을 추가했다 – Prastow