我在我的主tableView中,有一些自定义单元格(基本上是带有imageView的单元格)。重新加载searchResultsTableView
imageView仅当我的plist上的值为false时才设置。然后,当它是真的,imageView是零。
基本上当用户输入detailView时,该值设置为YES
,而cell.imageView
为零。
而且它好,它的工作原理
我使用的是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;
}
你是说你在进入详细视图之前某个特定的单元格会显示一张照片,但在你回来之后不会显示图片吗?它看起来像我正在缓存您的filteredResults值,并且如果您要更改幕后数据,我的猜测是过滤结果也不会被更新。 – 2012-07-08 03:27:59
基本上,当我回到视图的图像应该更新,但它只适用于删除搜索词,并再次搜索 – Phillip 2012-07-08 07:53:31
所以,正如我所说...它从代码片段看起来像你缓存你的filteredResults。因为它听起来像是在改变幕后结果的内容,所以您需要再次执行搜索(如您所建议的那样),或者当您在详细视图中更新某些内容时,您需要更新缓存的filteredResults以及其他结果。或者您需要更改filteredResults的内容,使其“项目不是您正在更改的内容的副本。 – 2012-07-08 17:27:31