代码之家  ›  专栏  ›  技术社区  ›  Boon

如何将自定义背景添加到uisearchdisplaycontroller的表视图?

  •  8
  • Boon  · 技术社区  · 15 年前

    我要将自定义uiImageView添加到uiSearchDisplayController的表视图背景,并将表视图的背景色设置为ClearColor。尝试了几种不同的方法,但找不到正确的解决方案。你知道怎么处理这个问题吗?

    注意:我不想添加到SearchDisplayController的SearchResultStableView的视图层次结构中,而是在其下方覆盖另一个同级视图)

    2 回复  |  直到 11 年前
        1
  •  25
  •   AJ.    14 年前

    您可以用与主表类似的方式设置背景图像,只在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]; }
    
        2
  •  3
  •   theTRON    13 年前

    您也可以在实例化 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;
    }