我在 if caption is None:
caption = sys.argv[0]
中有两个数组。一个包含图像的数组和一个包含标题的数组。
if caption is None:
caption = sys.argv[0].decode("utf8")
我有TableViewController
。
_ArrayTitle = [NSArray arrayWithObjects:@"Cat",@"Dog",@"Gnat", nil];
_ArrayImage = [NSArray arrayWithObjects:[UIImage imageNamed:@"Cat.jpg"],[UIImage imageNamed:@"Dog.jpg"],[UIImage imageNamed:@"Gnat.jpg"], nil];
我想在写作时得到结果" Cat"在searchdisplayController
中,当我搜索时,标题 - (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"SELF contains[cd] %@",
searchText];
_searchResults = [_ArrayTitle filteredArrayUsingPredicate:resultPredicate];
}
位于一个单元格中的图像searchBar
。
@"Cat"
此代码不起作用。当我写" Cat"," Dog"或者" Gnat"我得到" Cat.jpg"在所有细胞中。请帮我。
答案 0 :(得分:0)
你的if语句不是你的意思。变化:
if ([[_ArrayTitle objectAtIndex:indexPath.row]isEqualToString:@"Cat"]) {
cell.imageView.image = [_ArrayImage objectAtIndex:0];
}
if ([[_ArrayTitle objectAtIndex:indexPath.row]isEqualToString:@"Dog"]) {
cell.imageView.image = [_ArrayImage objectAtIndex:1];
}
if ([[_ArrayTitle objectAtIndex:indexPath.row]isEqualToString:@"Gnat"]) {
cell.imageView.image = [_ArrayImage objectAtIndex:2];
}
为:
if ([[_searchResults objectAtIndex:indexPath.row]isEqualToString:@"Cat"]) {
cell.imageView.image = [_ArrayImage objectAtIndex:0];
}
if ([[_searchResults objectAtIndex:indexPath.row]isEqualToString:@"Dog"]) {
cell.imageView.image = [_ArrayImage objectAtIndex:1];
}
if ([[_searchResults objectAtIndex:indexPath.row]isEqualToString:@"Gnat"]) {
cell.imageView.image = [_ArrayImage objectAtIndex:2];
}
您希望在索引路径中查看搜索结果中的标题,然后将该标题与图像匹配。