2012-12-19 3 views
4

검색 막대를 사용하여 TableView를 필터링하려고합니다. TableView에는 Imageview와 레이블이있는 사용자 정의 프로토 타입 셀이있어 호출 할 수 있습니다. 레이블은 이미지 아래에 숨겨져 있습니다.UISearchBar가 UITableView에서 사용자 지정 셀 이미지를 필터링하지 않습니다.

두 개의 배열에 각각 94 개의 항목이 있습니다. 아무것도 찾지 않으면 잘 작동합니다. 테이블 뷰는 이미지/셀을 완벽한 순서로 표시합니다.

검색 할 때 결과는 항상 적절한 수의 셀로 돌아옵니다. 그러나 이미지 자체는 필터링되지 않습니다. 즉, 어떤 셀이 레이블로 필터링 되더라도 이미지는 항상 동일합니다.

내 UISearchBar 코드에 문제가 있습니까?

-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {  
    if (searchText.length == 0) { 
     isFiltered = NO;  
    } else { 
     isFiltered = YES; 
     filteredHeroes = [[NSMutableArray alloc]init]; 

     for (NSString *str in totalHeroData) { 

      NSRange heroRange = [str rangeOfString:searchText options:NSCaseInsensitiveSearch]; 

      if (heroRange.location != NSNotFound) { 
       [filteredHeroes addObject:str]; 

      } 
     } } [self.HeroTableView reloadData]; } 

다른 자료를 기꺼이 제공합니다. 94 개의 항목으로 구성된 두 개의 배열이 있다는 것을 기억하십시오. 링크가 필요한 경우 해당 방법도 알고 싶습니다.

감사합니다.

편집 : 내가 당신은 내가 웹을 검색하는 약 10 시간을 보냈어요 :) 무엇을 생각하는지에 관해 알려주세요 asking-에 대한

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath 
*)indexPath {  
     static NSString *CellIdentifier = @"heroTableCell"; 
     HeroTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];  
     if (cell == nil) { 
     cell = [[HeroTableViewCell alloc] 
       initWithStyle:UITableViewCellStyleDefault 
       reuseIdentifier: CellIdentifier];  
     } 
     // Configure the cell... 
     cell.textLabel.text = [self.heroNames objectAtIndex:indexPath.row];    
     cell.imageView.image = [UIImage imageNamed:[self.heroImages objectAtIndex:indexPath.row]]; 

     return cell; 
    } 

감사 : 여기 Cellforrowatindexpath 방법은 S

+0

cellforrowatindexpath 메소드를 게시해야합니다. – iDev

+0

추가됨! cellforrowatindexpath 메소드 : – Nick

+0

searchBar에서 : textDidChange : filteredHeroes 배열의 데이터를 필터링하고 있습니다. cellForRowAtIndexPath에서 heroNames & heroImages를 사용하고 있습니다. 당신이 이것들을 어떻게 관련시키고 있는지 말할 수 있습니까? –

답변

0

당신이해야 하나 개 nsmutuable 배열을 사용하여 추가 한 키 참고 ImageName 및 문자열로 하나의 키 이름을 포함하는 NSDictionary에

[filteredHeroes addObject : [NSDictionary에 dictionaryWithObjectsAndKeys : 이름, "이미지"@ "이름", 참고 ImageName, @] 무기 호]
cellForRowAtIndexPath에서 동일한 filteredHeroes를 사용하고 키 이름을 사용하여 동일한 배열을 필터링하고 TableData를 다시로드하고 완료합니다.

관련 문제