我想添加一个自定义的UIImageView到UISearchDisplayController的表格视图背景,并将表格视图的背景颜色设置为clearColor。尝试了几种不同的方法,但找不到合适的解决方案。任何想法如何解决这个问题?如何将自定义背景添加到UISearchDisplayController的表视图?
注:我不想只会增加searchDisplayController的searchResultsTableView的视图层次,而是覆盖其下方的另一个兄弟视图)
我想添加一个自定义的UIImageView到UISearchDisplayController的表格视图背景,并将表格视图的背景颜色设置为clearColor。尝试了几种不同的方法,但找不到合适的解决方案。任何想法如何解决这个问题?如何将自定义背景添加到UISearchDisplayController的表视图?
注:我不想只会增加searchDisplayController的searchResultsTableView的视图层次,而是覆盖其下方的另一个兄弟视图)
你可以在你会为你的主表以类似的方式设置背景图片,将其设置在searchDisplayControllerDidBeginSearch委托方法中。例如: -
- (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller {
[controller.searchResultsTableView setDelegate:self];
UIImageView *anImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gradientBackground.png"]];
controller.searchResultsTableView.backgroundView = anImage;
[anImage release];
controller.searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
controller.searchResultsTableView.backgroundColor = [UIColor clearColor]; }
这对我工作! – adamweeks 2011-02-08 01:32:26
虽然这可以正常工作,但在'searchDisplayController:didLoadSearchResultsTableView:'中执行此操作可能更有意义。这样,您只需在必要时设置表格,而不是每次开始搜索。 (你也可以更方便地访问表视图,所以你可以使用'tableView'而不是'controller.searchResultsTableView'。) – robotspacer 2013-02-01 21:52:36
无论你实例化你的UISearchDisplayController
,你也可以做到这一点。在我的应用我在我UITableView
viewDidLoad
方法这样做的,是相匹配的两个表之间的风格:
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.separatorColor = [UIColor blackColor];
self.tableView.backgroundColor = [UIColor grayColor];
self.tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
searchController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
searchController.delegate = self;
searchController.searchResultsDataSource = self;
searchController.searchResultsDelegate = self;
searchController.searchResultsTableView.separatorColor = self.tableView.separatorColor;
searchController.searchResultsTableView.backgroundColor = self.tableView.backgroundColor;
searchController.searchResultsTableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
}
你找到一个方法来解决这个问题? – swalkner 2010-06-02 11:15:25
还没有得到解决方案呢。 – Boon 2010-06-03 17:07:45
您好, 我正在尝试自己做同样的事情。 您是否设法让此工作? 在此先感谢, 马特 – Sway 2011-02-03 07:02:17