I am trying to filter a TableView with a search bar. TableView has a custom prototype cell that has an Imageview and a shortcut so that it can be called up. The label is hidden under the image.
I have two arrays with 94 elements in each. It works great when not looking for anything. The table view displays the image / cell in perfect order.
When I search for something, the results always return with the appropriate number of cells. However, the images themselves are not filtered. This means that no matter which cells are filtered by label, the images will always be the same.
Is this a problem with my UISearchBar code?
-(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]; }
I would be happy to provide any other resources. Remember, I have two arrays of 94 items. If I need to connect them, I would also like to know how to do this.
Thanks.
EDIT: Here is the Cellforrowatindexpath method:
- (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]; }
Thank you for asking - let me know what you think :) I spent about 10 hours on the Internet: S
source share