我在这里有一个问题。在textDidChange函数中,我有NSMutableArray _setItem2和" name"," image"," price"列。在这种情况下,我能够通过" Name"列通过示例代码如下。
但是,我希望在搜索过滤后显示我的其他列值,例如价格和图片。我怎样才能做到这一点?请帮忙。
-(void)searchBar:(UISearchBar*)searchBar textDidChange:(NSString*)text
{
if(text.length == 0)
{
isFiltered = FALSE;
[searchBar resignFirstResponder];
}
else
{
isFiltered = true;
filteredTableData = [[NSMutableArray alloc] init];
for (NSDictionary *item in _setItem2) {
NSString *name = [item objectForKey:@"name"];
NSRange nameRange = [name rangeOfString:text options:NSCaseInsensitiveSearch];
if (nameRange.location != NSNotFound) {
[filteredTableData addObject:name];
}
}
}
[self.collectionView reloadData];
}
这是我的cellForItemAtIndexPath函数
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
DCListGridCell *cell = nil;
cell = (_isSwitchGrid) ? [collectionView dequeueReusableCellWithReuseIdentifier:DCListGridCellID forIndexPath:indexPath] : [collectionView dequeueReusableCellWithReuseIdentifier:DCSwitchGridCellID forIndexPath:indexPath];
if(isFiltered)
{
NSString *str1 = [filteredTableData objectAtIndex:indexPath.row];
//HOW CAN I SHOW IMAGE AND PRICE HERE??? NOW THE VALUE IS WRONG
//==============================================================
//cell.productImage = [[_setItem2 objectAtIndex:indexPath.row] image];
cell.productName = [filteredTableData objectAtIndex:indexPath.row];
//cell.productPrice = [[_setItem2 objectAtIndex:indexPath.row] price];
}
else
{
cell.productImage = [_setItem[indexPath.row]valueForKey:@"image"];
cell.productName = [_setItem[indexPath.row]valueForKey:@"name"];
cell.productPrice = [_setItem[indexPath.row]valueForKey:@"price"];
}
return cell;
}