1

當前我有此代碼將TableView中的默認背景更改爲自定義圖片,但是當用戶在UISearchBar中執行搜索時,搜索結果TableView是純白色背景。在哪裏/如何將其更改爲與我的常規非搜索TableView相同?在iOS中的UISearchResultsTableView中顯示自定義背景圖片

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     self.title = NSLocalizedString(@"Employee List", @"Employee List"); 
     if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { 
      self.clearsSelectionOnViewWillAppear = NO; 
      self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0); 
     } 
     else { 
      { 
       UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Cloth.png"]]; 
       [tempImageView setFrame:self.tableView.frame]; 

       self.tableView.backgroundView = tempImageView; 
      } 
     } 
    } 
    return self; 
} 

回答

1

您應該能夠通過searchDisplay控制器訪問SearchResult所的TableView:

... 
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Cloth.png"]]; 
[tempImageView setFrame:self.tableView.frame]; 

self.tableView.backgroundView = tempImageView; 
self.searchDisplayController.searchResultsTableView.backgroundView = tempImageView; 
... 
+0

輝煌!謝謝。 – OscarTheGrouch 2012-08-06 00:15:12