検索バーで TableView をフィルタリングしようとしています。TableView には、Imageview とラベルを持つカスタム プロトタイプ セルがあり、呼び出すことができます。ラベルは画像の下に隠れています。
それぞれに94個のアイテムを持つ2つの配列があります。何も検索されていない場合は正常に機能します。テーブルビューには、画像/セルが完全な順序で表示されます。
何かを検索すると、結果は常に適切な数のセルで返されます。ただし、画像自体はフィルタリングされません。これは、どのセルがラベルでフィルタリングされても、画像は常に同じであることを意味します。
これは私の 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 項目の配列が 2 つあることを思い出してください。それらをリンクする必要がある場合は、その方法も知りたいです。
ありがとうございました。
編集: 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 時間費やしました :S