0

我试图让我的searchResultsTableView内返回的单元格看起来与“常规”,非搜索表格视图中的单元格相似。这是我的regular view获取多个表视图实例以匹配

第一次搜索时,结果的样式与“常规”表格视图完全相同。但是,一旦您取消了searchDisplayController并再次点击搜索按钮,you'll get this

它看起来像在第一次加载搜索显示控制器后没有设置背景。

我使用UITableViewCell实例化tableView:cellForRowAtIndexPath:中的单元格,而不是自定义子类。下面是该方法的其余部分:

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]; 

回答

0

移动代码样式化searchResultsTableViewsearchDisplayController:willShowSearchResultsTableView: ,一个UISearchDisplayDelegate的方法,负责这个。