Note that there are some explanatory texts on larger screens.

plurals
  1. POSearchDisplayController searching in multiple arrays
    text
    copied!<p>Okay, after long searching, hesitating and more searching I just can't seem to figure this out.</p> <p>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.).</p> <p>I now have 4 search-arrays, search_title, search_description etc which are filled like this:</p> <pre><code>- (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]; </code></pre> <p>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.</p> <p>My tableview cell looks like this:</p> <pre><code>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]; </code></pre> <p>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.</p> <p>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.</p> <p>Can someone please give me a hint in the good direction, or examples which I can use?</p> <p>Thank you in advance.</p> <p>Prastow</p> <p>References I used:</p> <p><a href="https://stackoverflow.com/questions/8169889/searchdisplaycontroller-search-multiple-arrays">SearchDisplayController search multiple arrays</a></p> <p><a href="http://ygamretuta.me/2011/08/10/ios-implementing-a-basic-search-uisearchdisplaycontroller-and-interface-builder/" rel="nofollow noreferrer">http://ygamretuta.me/2011/08/10/ios-implementing-a-basic-search-uisearchdisplaycontroller-and-interface-builder/</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload