さて、長い間検索し、躊躇し、さらに検索した後、私はこれを理解できないようです.
SearchDisplayController があり、NSPredicate を使用して検索する 4 つの異なる配列があります。これは、各 UITableViewCell が 4 つの文字列 (タイトル、説明など) で構成されているためです。
私は今、次のように入力された4つの検索配列、search_title、search_descriptionなどを持っています:
- (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];
NSLog (配列カウント) を使用すると、検索語を入力すると各配列の正しいカウントが得られるため、機能していることがわかります。
私のテーブルビューセルは次のようになります。
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];
私が何をしようとしているのか、もうお分かりかもしれません。私は現在、古い配列から新しい配列を作成しています。これを検索配列と呼んでいます。ただし、これらの配列は互いに独立しています (1 つの配列が空で、もう 1 つの配列が researchresult で満たされている場合があります)。これらの検索配列に格納されているデータがどのインデックスからのものかを知る必要があります。search_producttitle のデータが price_producttitle (元の配列) のインデックス 1、3、および 4 に由来することがわかっている場合は、それらの数値を indexPath.row に使用して表示できます。少なくとも、セルを作成するときに objectAtIndex で使用する必要がある数値を含む searchResult 配列を作成することが、今のところ私の計画です。
セルが複数の配列で構成されているため、複数の配列内で検索している例が見つかりません。
誰かが私に良い方向へのヒント、または私が使用できる例を教えてもらえますか?
前もって感謝します。
プラストー
私が使用した参照: