【发布时间】:2014-02-21 17:52:48
【问题描述】:
我有一个完美运行的 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;
}
这很好用。 单击 SearchBar 并开始输入时出现问题。
这是进行此搜索的代码。
- (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]; 行有问题
这是我的输出 Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__nscfconstantstring> valueForUndefinedKey:]: 这个类不是键值编码兼容键 _rotulos。'
我关注这个Tutorial,但在我的情况下,_rotulos 不是某个类的属性,是一个 NSArray。
我该如何解决? 抱歉,如果忘记发布内容。
【问题讨论】:
标签: ios7 uitableview uisearchbar uisearchbardisplaycontrol