2016-02-24 44 views
0

當我搜索和過濾後選擇顯示只打開第一個字母DetailView(例如一個字母)的行。其他字母不打開。 NSLog和斷點沒有幫助。我不明白是什麼問題。TableViewController,SearchBar和TableViewCell

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 

     NSString *keyTitle = cell.textLabel.text; 

     NSDictionary *peopleUnderLetter = [self.propertyList objectForKey:self.letters[indexPath.section]]; 

     __block NSDictionary *selectedPerson = nil; 

     [peopleUnderLetter enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) { 

      if ([key isEqualToString:keyTitle]) { 

       selectedPerson = obj; 

       *stop = YES; 

      } 

     }]; 

     if (selectedPerson) { 

      DetailViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"]; 
      // Push the view controller. 
      [self.navigationController pushViewController:vc animated:YES]; 

      [vc setDictionaryGeter:selectedPerson]; 
     } 

    } 

#pragma mark Search Display Delegate Methods 

-(void)searchDisplayController:(UISearchController *)controller didLoadSearchResultsTableView:(UITableView *)tableView { 
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"]; 
} 

-(BOOL)searchDisplayController:(UISearchController *)controller shouldReloadTableForSearchString:(NSString *)searchString 

{ 

    [filteredNames removeAllObjects]; 
    if (searchString.length > 0) { 
     NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF contains [search] %@", self.searchBar.text]; 

     for (NSString *letter in letters) { 
      NSArray *matches = [[self.propertyList[letter] allKeys]filteredArrayUsingPredicate:predicate]; 

      [filteredNames addObjectsFromArray:matches]; 

     } 

    } 

    return YES; 

} 

選擇每一個細胞都必須打開他們的data.Search欄detailviewcontroller後顯示filtered.But後的每一封信,當我點擊細胞不公開細節視圖(除了第一個單元格)。

回答

3

很難說沒有看到整個文件,但它看起來像你的問題可能是這條線。您正在使用部分而不是將object拖出self.propertyList。這是有道理的,爲什麼它僅適用於第一行,這將有0行和0

`NSDictionary *peopleUnderLetter = [self.propertyList objectForKey:self.letters[indexPath.section]];` 

嘗試將其更改爲一個部分:

`NSDictionary *peopleUnderLetter = [self.propertyList objectForKey:self.letters[indexPath.row]];` 
+0

感謝您的幫助。但沒有任何改變。 –

+0

如果你需要更多的信息,只需用答案對我說,然後我將編輯我的問題,然後你將編輯你的答案 –

+0

如果你在上面的一行放置了一個斷點「if(selectedPerson){」,然後點擊一行以外的行第一行是selecterPerson nil? – naomimichiko