gpt4 book ai didi

ios - 如何根据ios中搜索到的项目调整图像?

转载 作者:行者123 更新时间:2023-11-29 01:46:06 24 4
gpt4 key购买 nike

我可以使用 UISearch 栏来过滤表中的列表,一切正常,但正确图像中的问题未根据文本显示...请参见下图。任何帮助都会被应用... Initial image before search

After Search

  -(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {



if(searchText.length == 0)
{
_isFiltered = FALSE;
}
else{
// NSPredicate *resultPredicate=[NSPredicate predicateWithFormat:@"(SELF.name contains[cd] %@)or(SELF.rank contains[cd] %@)or(SELF.score contains[cd] %@)",searchText,searchText,searchText];
NSPredicate *resultPredicate=[NSPredicate predicateWithFormat:@"(SELF contains[cd] %@)",searchText];
self.filteredTableData = [self.searchItemsArray filteredArrayUsingPredicate:resultPredicate];
NSLog(@"Predicated array %@", self.filteredTableData);
self.isFiltered = YES;
if (self.filteredTableData.count == 0) {
[[CLAlertHandler standardAlertHandler]showAlert:@"No match found!" title:AppName];
}
}
//[self.searchTableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
[self.searchTableView reloadData];
}


(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
SearchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if(cell == nil)
cell = [[SearchTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
if (_isFiltered) {
cell.itemNameLabel.text = [self.filteredTableData objectAtIndex:indexPath.row];
cell.iconImageView.image = [UIImage imageNamed:[self.searchImagesArray objectAtIndex:indexPath.row]];
}
else
{
cell.itemNameLabel.text = [self.searchItemsArray objectAtIndex:indexPath.row];
cell.iconImageView.image = [UIImage imageNamed:[self.searchImagesArray objectAtIndex:indexPath.row]];
}
return cell;
}

最佳答案

if (_isFiltered) {
...
cell.iconImageView.image = [UIImage imageNamed:[self.searchImagesArray objectAtIndex:indexPath.row]];
}
else
{
...
cell.iconImageView.image = [UIImage imageNamed:[self.searchImagesArray objectAtIndex:indexPath.row]];
}

当您在两个分支中执行相同的代码时,if 子句中的要点是什么?我会说你应该在 if 和 else 分支中做一些不同的事情。例如。从另一个数组中获取图像的另一个名称。

有点像

if (_isFiltered) {
cell.itemNameLabel.text = [self.filteredTableData objectAtIndex:indexPath.row];
cell.iconImageView.image = [UIImage imageNamed:[self.filteredImagesArray objectAtIndex:indexPath.row]];
}
else
{
cell.itemNameLabel.text = [self.searchItemsArray objectAtIndex:indexPath.row];
cell.iconImageView.image = [UIImage imageNamed:[self.searchImagesArray objectAtIndex:indexPath.row]];
}

关于ios - 如何根据ios中搜索到的项目调整图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31914411/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com