为什么在设置tableview背景图像时,tableview单元几乎不可见?

时间:2010-02-07 05:46:19

标签: iphone uitableview uisearchdisplaycontroller

使用背景图片加载时,无法使searchResultsTableView单元格完全可见。细胞看起来很弱,即使在选中时也不会从背景图像视图中脱颖而出。有什么建议吗?

- (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView {

    for (UIView *view in controller.searchResultsTableView.subviews) {
        //if ([view isKindOfClass:[UIImageView class]]) {
            [view removeFromSuperview];
        //}
    }

    UIImage *patternImage = [UIImage imageNamed:@"background_newer.png"];
    UIImageView * backgroundImageView = [[UIImageView alloc] initWithImage:patternImage];
    //backgroundImageView.opaque = NO;
    backgroundImageView.alpha = 0.9;

    controller.searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    controller.searchResultsTableView.backgroundColor = [UIColor clearColor];
    [controller.searchResultsTableView addSubview:backgroundImageView];
    [controller.searchResultsTableView sendSubviewToBack:backgroundImageView];
    controller.searchResultsTableView.rowHeight = 25;

    [patternImage release];
    [backgroundImageView release];  
}

除了在此委托方法中分配新的UITableViewCell(在searchResultsTableView中)之外,我没有做任何其他事情:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { .... } 

感谢您的任何更正!

(我在iPhone模拟器3.1.2上)

3 个答案:

答案 0 :(得分:1)

@Jessedc

感谢您的建议。尚未尝试过您的代码。

我解决了这个问题(在我看到你的回复之前),每当searchResultsTableView加载时,在searchResultsTableView后面的主tableview上设置hidden = YES,并在搜索结束时隐藏= NO。主tableview在imageview上设置了backgroundColor = [UIColor clearColor](加载了与我原来的searchResultsTableView代码相同的图像)。

这种新布局如前所述: - )。

答案 1 :(得分:1)

是否尝试显示静态背景图片,表格文字滚动到顶部? 我想你的代码可能会混淆(可能)。

自定义表通常在viewWillAppear方法中完成。所以这段代码应该去那里:

UIImage *patternImage = [UIImage imageNamed:@"background_newer.png"];
UIImageView * backgroundImageView = [[UIImageView alloc] initWithImage:patternImage];
//backgroundImageView.opaque = NO;
backgroundImageView.alpha = 0.9;

controller.searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
controller.searchResultsTableView.backgroundColor = [UIColor clearColor];
[controller.searchResultsTableView addSubview:backgroundImageView];
[controller.searchResultsTableView sendSubviewToBack:backgroundImageView];
controller.searchResultsTableView.rowHeight = 25;

[patternImage release];
[backgroundImageView release]; 

接下来,在您的委托方法 searchDisplayController:willShowSearchResultsTableView 中,您不是指传入的tableview对象,而是通过顶层调用它(不必要吗?)

将表格设置代码移动到viewWillAppear中。 如果这有帮助,或者您可以提供更多信息/代码,请告诉我。

答案 2 :(得分:0)

在我看来,你正在努力设置你的桌面视图的背景。我不知道这是100%的问题,但你应该像这样设置你的UITableView背景:

controller.searchResultsTableView.backgroundColor = [[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"background_newer.png"]]autorelease];

相关问题