2009-10-24 37 views
8

Tôi muốn thêm UIImageView tùy chỉnh vào nền xem bảng của UISearchDisplayController và đặt màu nền của chế độ xem bảng thành clearColor. Đã thử một vài cách tiếp cận khác nhau nhưng không thể tìm ra giải pháp phù hợp. Bất kỳ ý tưởng làm thế nào để tiếp cận này?Cách thêm nền tùy chỉnh vào chế độ xem bảng của UISearchDisplayController?

Lưu ý: Tôi không muốn thêm vào hệ thống phân cấp view searchDisplayController của searchResultsTableView, nhưng thay vì che phủ khác xem anh chị em dưới nó)

+0

bạn đã tìm ra cách để giải quyết này? – swalkner

+0

Chưa có giải pháp cho việc này. – Boon

+0

Xin chào, Tôi đang cố gắng làm điều tương tự. Bạn có quản lý để làm việc này không? Xin cảm ơn trước, Matt – Sway

Trả lời

25

Bạn có thể thiết lập các hình nền theo cách tương tự bạn sẽ cho bảng chính của bạn, chỉ đặt nó trong phương thức delegate SearchDisplayControllerDidBeginSearch. Ví dụ: -

- (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]; } 
+0

Điều này làm việc cho tôi! – adamweeks

+5

Trong khi điều này hoạt động tốt, nó có thể có ý nghĩa hơn để làm điều này trong 'searchDisplayController: didLoadSearchResultsTableView:'. Bằng cách đó, bạn chỉ thiết lập bảng khi cần thiết, thay vì mỗi lần tìm kiếm được bắt đầu. (Bạn cũng có thể truy cập thuận tiện hơn vào chế độ xem bảng, vì vậy bạn có thể sử dụng 'tableView' thay vì' controller.searchResultsTableView'.) – robotspacer

3

Bạn cũng có thể thực hiện việc này bất cứ nơi nào bạn tạo nhanh UISearchDisplayController. Trong ứng dụng của tôi, tôi đã làm điều này trong phương pháp UITableViewviewDidLoad của tôi và đã phù hợp với phong cách giữa hai bảng:

- (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; 
} 
Các vấn đề liên quan