重新加载 searchResultsTableView [英] Reloading searchResultsTableView

查看:79
本文介绍了重新加载 searchResultsTableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的主 tableView 中有一些自定义单元格(基本上是带有 imageView 的单元格).

I have, in my main tableView, some custom cells (cells with an imageView, basically).

仅当我的 plist 上的值为 false 时才设置 imageView.然后,当它为真时,imageView 为零.

The imageView is set only if a value on my plist is false. Then, when it's true, the imageView is nil.

基本上当用户进入detailView时,值设置为YEScell.imageView为nil.

Basically when the user enters the detailView, the value is set to YES and the cell.imageView is nil.

没关系,它有效

我正在使用 searchDisplayController,当我搜索具有 cell.imageView 的内容时,进入 detailView,然后返回到 searchResultsTable,即单元格仍然有图像,虽然它不应该,但主 tableView 具有正确的单元格(因此,没有图像).

I'm using a searchDisplayController, when i search for something that has a cell.imageView, going into the detailView and then coming back to the searchResultsTable, the cell has still the image, while it shouldn't, but the main tableView has the correct cell (so, with no image).

我认为它可能取决于 searchResultsTableView,但我不确定.我试过

I thought that it could depend on searchResultsTableView, but i'm not sure. I tried with

[self.searchDisplayController.searchResultsTableView reloadData]; 

没有效果.

我如何重新加载 searchResultsTableView 以便它显示正确的单元格、那些有图像的单元格和那些不再有图像的单元格?

How could i reload the searchResultsTableView so that it shows the right cells, those with the image and those that don't have the image anymore?

感谢任何帮助!

编辑

这是我的 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;
}

推荐答案

如果我理解正确,那么您可以有一个解决方法,但使用相同的搜索字符串再次搜索:

If I understood you right, then you can have a workaround but searching again with the same search string:

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

将它放在 viewWillAppear:viewDidAppear: 中,每次显示视图时都会调用它们(例如,您从 detail view 到您的 搜索视图).在这个地方重新加载数据也很好,以获得正确的数据(例如,如果您在示例代码中将单元格标记为已读)

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)

只是[self.tableView reloadData]; 而不是searchResultsTableView(它会在新搜索后自动使用更新的数据)

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

这篇关于重新加载 searchResultsTableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆