1

안녕하세요 어떤 응답을 사전에 모두 감사.오브젝티브 C는, iPad는 : DetailView 만 필터링 할 때 첫 번째 행에서 값을 표시

은 내가 MasterDetail보기 인 아이 패드 응용 프로그램을 만들고있어. 이 테이블은 이름 목록 (NSDictionary의 키)을 표시하고 Detail View는 각 이름 (NSDictionary의 값)과 연관된 이미지를 표시합니다. 표에 이름을 필터링하는 검색이 있습니다.

은 사전 @ 말할 수 있습니다 {@ "존": "Star.png"@ "마리아"@ "Circle.png"@}를. John이 테이블의 첫 번째 위치에 있으므로 첫 번째 행이 선택되면 별 이미지가 표시됩니다. 메리는 두 번째 위치에 있으며 그 행이 선택되면 표시되는 원입니다.

문제 : 나는 필터링하고 마리아를 검색하면 자, 그 이름은 첫 번째 행을 차지합니다. 행을 선택하면 서클 대신 별이 표시됩니다. 아래

코드 : 인덱싱에 대한

사전 및 배열

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]; 

didSelectRow

- (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]; 
    } 
} 
} 

내 생각 엔 문제가 필터로 인해 발생합니다. 내가 맞습니까? 어떤 제안이나 추가 정보가 필요합니까? 다시 한번 감사드립니다. 여과시

답변

0

사용 된 값은 정확하지 않다.

- (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 
} 
+0

그게 내가 생각한거야, 그것을 처리하는 가장 좋은 방법은 확실하지 않았다. 오늘 직장에서 집에 돌아와서 바로 결과를보고하면 이걸 시도 할게. 감사! – Klos225

+0

다른 배열로 가지는 대신 사전에서 가져와야합니다. 내 대답이 업데이트되었습니다. –

+0

감사합니다. 나는 실제로 다른 모든 것을 그대로 유지하고 그 한 줄을 조정합니다. 나는 현재 가지고있는 것을 최적화 할 방법이 있다고 확신합니다. 당분간, 이것은 할 것이다. – Klos225

0

편집

난 당신의 코드에서 볼 수있는 유일한 문제는 당신이 값을 가져 오는 방법은 다음과 같습니다 대신

detailViewController.tablePicture.image = values[indexPath.row];

이 작업을 수행 :

detailViewController.tablePicture.image = [attendees valueForKey:detailViewController.detailLabel.text];