私は完全に機能するTableViewを持っていました。で検索を含めましTableView
たSearchBar component and Display ViewController
。NSArray _rotulos によって取り込まれたラベルに基づいて検索を実行したいと考えています。
@property (nonatomic, strong) NSArray *rotulos;
viewDidLoad メソッドにコンテンツを入力します (オブジェクトは他にもありますが、これは単なる例です)
_rotulos = @[@"Item 1", @"Item 2", @"Item 3", @"Block 1", @"Block 2",@"Block 3"];
cellForRowAtIndexPath メソッドに入力します
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"TableCell";
TableCell *cell = (TableCell *)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//Configure the cell...
if (cell == nil) {
cell = [[TableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
long row = [indexPath row];
cell.rotuloLabel.text = _rotulos[row];
cell.descricaoLabel.text = _vinicola[row];
cell.uvaLabel.text = _uva[row];
return cell;
}
これはうまくいきます。検索バーをクリックして入力を開始すると問題が発生します。
この検索を行うコードは次のとおりです。
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"_rotulos contains[c] %@", searchText];
searchResults = [recipes filteredArrayUsingPredicate:resultPredicate];
}
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString
scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
objectAtIndex:[self.searchDisplayController.searchBar
selectedScopeButtonIndex]]];
return YES;
}
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"_rotulos contains[c] %@", searchText];
This is my output Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFConstantString 0x243c8> valueForUndefinedKey:]: this class is not key valuecoding-compliant for the key _rotulos.' という行に問題があります。
私はこのチュートリアルに従いますが、私の場合、_rotulos は一部のクラスのプロパティではなく、NSArray です。
どうすれば修正できますか?何かを投稿するのを忘れていたらごめんなさい。