Ios UISearchBar未从UITableView筛选自定义单元格图像

Ios UISearchBar未从UITableView筛选自定义单元格图像,ios,xcode,uitableview,uisearchbar,Ios,Xcode,Uitableview,Uisearchbar,我正在尝试使用搜索栏筛选TableView。TableView有一个自定义的原型单元,该单元有一个Imageview和一个标签,因此可以调用它。标签隐藏在图像下方 我有两个数组,每个数组中有94个项目。当没有搜索到任何东西时,它工作得很好。tableview以完美的顺序显示图像/单元格 当我搜索某样东西时,结果总是带着适当数量的单元格返回。但是,图像本身不会被过滤。这意味着,无论标签过滤了哪些单元格,图像都将始终相同 这是我的UISearchBar代码的问题吗 -(void)searchBar:

我正在尝试使用搜索栏筛选TableView。TableView有一个自定义的原型单元,该单元有一个Imageview和一个标签,因此可以调用它。标签隐藏在图像下方

我有两个数组,每个数组中有94个项目。当没有搜索到任何东西时,它工作得很好。tableview以完美的顺序显示图像/单元格

当我搜索某样东西时,结果总是带着适当数量的单元格返回。但是,图像本身不会被过滤。这意味着,无论标签过滤了哪些单元格,图像都将始终相同

这是我的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项数组。如果我需要链接他们,我想知道如何做到这一点以及

多谢各位

编辑:以下是Cellforrowatindexpath方法:

- (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; 
   }
谢谢你的提问-让我知道你的想法:)
我花了大约10个小时搜索web:S

您应该使用一个NSmutualable数组并添加nsdictionary,其中包含一个键imagename和一个键名作为字符串

[filteredHeroes addObject:[NSDictionary Dictionary WithObjectsAndKeys:name、@“name”、ImageName、@“Image”、nil]

在cellForRowAtIndexPath中使用相同的Filteredheros,并使用键名过滤相同的数组,然后重新加载TableData并完成。

您需要发布cellForRowAtIndexPath方法。已添加!searchBar:textDidChange中的cellforrowatindexpath方法:)正在筛选Filteredheros数组中的数据,而cellforrowatindexpath中使用的是heroNames和HeroMages。你能告诉我你是如何关联这些的吗?@Nick,你已经过滤了
filteredheros
而不是
heroNames
heromages
数组。你也需要过滤它。