我试图让我返回的单元格searchResultsTableView
看起来就像“常规”非搜索表视图中的单元格。这是我的常规观点。
第一次搜索时,结果的样式与“常规”表格视图完全相同。然而,一旦你取消了 searchDisplayController 并再次点击 Search 按钮,你就会得到这个.
在我看来,在第一次加载搜索显示控制器后没有设置背景。
我在tableView:cellForRowAtIndexPath:
using中实例化单元格UITableViewCell
,而不是自定义子类。这是该方法的其余部分:
PersonInfo *info = nil;
if (tableView == self.searchDisplayController.searchResultsTableView) {
info = [self.filteredPeopleList objectAtIndex:indexPath.row];
} else {
info = [self.peopleList objectAtIndex:indexPath.row];
}
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellBk.png"]];
cell.detailTextLabel.textColor = [UIColor whiteColor];
cell.backgroundColor = [UIColor clearColor];
cell.imageView.image = info.image;
cell.textLabel.text = info.name;
cell.detailTextLabel.text = info.title;
return cell;
(tableView
“常规”)并且searchResultsTableView
在内部设置如下viewDidLoad
:
//Set the default tableView style
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.opaque = NO;
self.tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]];
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
//Set the self.searchDisplayController background stuff
self.searchDisplayController.searchResultsTableView.backgroundColor = [UIColor clearColor];
self.searchDisplayController.searchResultsTableView.opaque = NO;
self.searchDisplayController.searchResultsTableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]];
[self.searchDisplayController.searchResultsTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
[self.tableView reloadData];