Okay, after long searching, hesitating and more searching I just can't seem to figure this out.
I have a SearchDisplayController, and I have four different arrays where I am searching in using NSPredicate, because each UITableViewCell is made out of 4 strings (title, description etc.).
I now have 4 search-arrays, search_title, search_description etc which are filled like this:
- (void)filterContentForSearchText:(NSString*)searchText
scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"SELF contains[cd] %@",
searchText];
self.search_category = [self.temp_category filteredArrayUsingPredicate:resultPredicate];
self.search_producttitle = [self.price_producttitle filteredArrayUsingPredicate:resultPredicate];
self.search_type = [self.price_type filteredArrayUsingPredicate:resultPredicate];
self.search_description = [self.price_description filteredArrayUsingPredicate:resultPredicate];
When I use NSLog (array count), I can see it's working because it gives the correct count of each array when I enter a search term.
My tableview cell looks like this:
if ([tableView isEqual:self.searchDisplayController.searchResultsTableView]){
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.nameLabel.text = [self.search_producttitle objectAtIndex:[[searchResults objectAtIndex:indexPath.row] integerValue]];
cell.priceLabel.text = [self.search_price objectAtIndex:[[searchResults objectAtIndex:indexPath.row] integerValue]];
cell.descrLabel.text = [self.search_description objectAtIndex:[[searchResults objectAtIndex:indexPath.row] integerValue]];
cell.IDLabel.text = [self.search_type objectAtIndex:[[searchResults objectAtIndex:indexPath.row] integerValue]];
}
else{
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.nameLabel.text = [price_producttitle objectAtIndex:indexPath.row];
cell.IDLabel.text = [price_type objectAtIndex:indexPath.row];
cell.priceLabel.text = [price objectAtIndex:indexPath.row];
cell.descrLabel.text = [price_description objectAtIndex:indexPath.row];
Maybe you can already see what I'm trying to do. I'm now making new arrays from the old arrays, which I call search arrays. However, those arrays are independent from each other (one array may be empty while the other is filled with researchresults). I need to know from which index the data is, that is stored in those searcharrays. If i know that the data in search_producttitle comes from indexes 1,3 and 4 from price_producttitle (the original array), then I can use those numbers for indexPath.row to show. At least, that's my plan for now, making a searchResult array containing numbers which should be used in the objectAtIndex when making the cell.
I'm struggling with this, I can't find any examples where they are searching within multiple arrays because the cells are made up by multiple arrays.
Can someone please give me a hint in the good direction, or examples which I can use?
Thank you in advance.
Prastow
References I used: