1

メインのtableViewには、いくつかのカスタムセル(基本的にはimageViewを持つセル)があります。

imageViewは、plistの値がfalseの場合にのみ設定されます。次に、それがtrueの場合、imageViewはnilです。

基本的に、ユーザーがdetailViewに入ると、値はに設定されYEScell.imageViewはnilになります。

そしてそれは大丈夫です、それは機能します

を使用しsearchDisplayControllerています。cell.imageViewを持つものを検索し、detailViewに移動してから戻るとsearchResultsTable、セルにはまだ画像がありますが、そうではないはずですが、メインのtableViewには正しいセルがあります。 (つまり、画像なし)。

searchResultsTableViewに依存する可能性があると思いましたが、よくわかりません。で試してみました

[self.searchDisplayController.searchResultsTableView reloadData]; 

効果はありません。

searchResultsTableViewをリロードして、正しいセル、画像のあるセル、画像のないセルを表示するにはどうすればよいですか?

助けていただければ幸いです。

編集

これが私のcellForRowAtIndexPath方法です:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }


    NSArray *rows;
    if (tableView == self.searchDisplayController.searchResultsTableView) {
        rows = filteredList; //for search
    } else {
        NSDictionary *section = [localSortedTips objectAtIndex:indexPath.section];
        rows = [section objectForKey:@"Rows"];
    }

    NSDictionary *item = [rows objectAtIndex:indexPath.row];
    cell.textLabel.text = [item objectForKey:@"name"];  
    if ([[item valueForKey:@"isRead"] boolValue] == NO) {
        cell.imageView.image = [UIImage imageNamed:@"unread.png"];
    } else {
        cell.imageView.image = nil;
    }
    cell.textLabel.font = [UIFont boldSystemFontOfSize:15.0];
    cell.textLabel.adjustsFontSizeToFitWidth = YES;

    return cell;
}
4

2 に答える 2

6

私があなたを正しく理解していれば、回避策を講じることができますが、同じ検索文字列でもう一度検索します。

if (self.searchDisplayController.active) {
    self.searchDisplayController.searchBar.text = self.searchDisplayController.searchBar.text;
}

put it in viewWillAppear: or viewDidAppear: which will be called each time the view is shown up (eg. you go back from the detail view to your search view). And reloading the data in this place would be nice too, to get the right data (for example if you marked the cell as read like in your sample code)

Just [self.tableView reloadData]; and not the searchResultsTableView (it will be automatically use the updated data after the new search)

于 2012-07-08T23:10:51.987 に答える
0

おそらくあなたの細胞がリサイクルされていて、適切にリセットされていないように聞こえます。UITableViewはビューのリサイクルを使用するため、画像を設定するなどの操作を行う場合は、表示する画像でなくても、明示的に設定されていることを確認することが重要です。

あなたがあなたのcellsForRowAtIndexPathコードを共有するならば、あなたはもう少し助けを得ることができるかもしれません。

于 2012-07-06T21:31:12.613 に答える