1

目前我有这段代码将 TableView 中的默认背景更改为自定义图片,但是当用户在 UISearchBar 中进行搜索时,搜索结果 TableView 是纯白色背景。我在哪里/如何将其更改为与我的常规非搜索 TableView 相同?

    - (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;
}
4

1 回答 1

1

您应该能够通过 searchDisplay 控制器访问 searchResults TableView:

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

self.tableView.backgroundView = tempImageView;
self.searchDisplayController.searchResultsTableView.backgroundView = tempImageView;
...
于 2012-08-03T06:59:02.567 回答