Ios Objective-C,iPad:DetailView仅显示过滤时第一行的值
大家好,提前感谢大家的回复 我正在制作一个iPad应用程序,它是一个MasterDetail视图。该表显示NSDictionary中的名称键列表,“详细信息”视图显示与NSDictionary中的每个名称和值关联的图像。该表包含用于筛选名称的搜索 比如说一本字典{@John:@Star.png、@Mary:@Circle.png}。John位于表格的第一个位置,因此当选择第一行时,将显示一个星形图像。Mary位于第二个位置,当选择该行时,将显示一个圆圈 问题是: 现在,如果我过滤并搜索玛丽,这个名字将占据第一行。如果选择该行,将显示一个星形而不是圆形 代码如下: 用于索引的字典和数组Ios Objective-C,iPad:DetailView仅显示过滤时第一行的值,ios,objective-c,ipad,master-detail,didselectrowatindexpath,Ios,Objective C,Ipad,Master Detail,Didselectrowatindexpath,大家好,提前感谢大家的回复 我正在制作一个iPad应用程序,它是一个MasterDetail视图。该表显示NSDictionary中的名称键列表,“详细信息”视图显示与NSDictionary中的每个名称和值关联的图像。该表包含用于筛选名称的搜索 比如说一本字典{@John:@Star.png、@Mary:@Circle.png}。John位于表格的第一个位置,因此当选择第一行时,将显示一个星形图像。Mary位于第二个位置,当选择该行时,将显示一个圆圈 问题是: 现在,如果我过滤并搜索玛丽,这个
attendees =[NSDictionary dictionaryWithObjectsAndKeys:[UIImage imageNamed:@"Flake1.png"],@"John",[UIImage imageNamed:@"Flake2.png"],@"Mary",[UIImage imageNamed:@"Flake3.png"], @"Bob", nil];
keys = [attendees allKeys];
values = [attendees allValues];
迪德罗
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (isSearching && [filteredList count]) {
//If the user is searching, use the list in our filteredList array.
detailViewController.title = [filteredList objectAtIndex:indexPath.row];
detailViewController.detailLabel.text = [filteredList objectAtIndex:indexPath.row];
detailViewController.tablePicture.image = values[indexPath.row];
} else {
detailViewController.title = keys[indexPath.row];
detailViewController.detailLabel.text = keys[indexPath.row];
detailViewController.tablePicture.image = values[indexPath.row];
过滤
- (void)filterListForSearchText:(NSString *)searchText
{
[filteredList removeAllObjects]; //clears the array from all the string objects it might contain from the previous searches
for (NSString *title in attendees) {
NSRange nameRange = [title rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (nameRange.location != NSNotFound) {
[filteredList addObject:title];
}
}
}
我猜问题是由过滤器引起的。我说得对吗?有什么建议或需要其他信息吗?再次感谢。过滤时使用的值不正确
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (isSearching && [filteredList count]) {
//If the user is searching, use the list in our filteredList array.
detailViewController.title = [filteredList objectAtIndex:indexPath.row];
detailViewController.detailLabel.text = [filteredList objectAtIndex:indexPath.row];
detailViewController.tablePicture.image = [attendees valueForKey:filteredList[indexPath.row]]; //Use this line instead
}
编辑
我在代码中看到的唯一问题是如何获取值:
而不是
detailViewController.tablePicture.image=值[indexPath.row]
这样做:
detailViewController.tablePicture.image = [attendees valueForKey:detailViewController.detailLabel.text];
这就是我想的,我不确定最好的处理方法。我今晚下班回家后会试试这个,然后马上报告结果。谢谢不要将其作为不同的数组,而是从字典中获取它。更新了我的答案。这很有效,谢谢。实际上,我保持了其他一切的原样,只是调整了那一行。我相信有办法优化我目前拥有的。但就目前而言,这就足够了。