在iOS中的UISearchResultsTableView中显示自定义背景图片

时间:2012-07-25 03:06:39

标签: uitableview ios4 uisearchdisplaycontroller ios5 uisearchresultscontroller

目前我有这个代码将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;
}

1 个答案:

答案 0 :(得分: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;
...