开发者

Why are tableview cells hardly visible when setting tableview background image?

I can't get the searchResultsTableView cells to be fully visible when loading with a background image. The cells look quite weak and don't stand out from the background imageview, even when selected. Any suggestions?

- (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 = [UICo开发者_开发知识库lor clearColor];
    [controller.searchResultsTableView addSubview:backgroundImageView];
    [controller.searchResultsTableView sendSubviewToBack:backgroundImageView];
    controller.searchResultsTableView.rowHeight = 25;

    [patternImage release];
    [backgroundImageView release];  
}

I am not doing anything else than allocating a new UITableViewCell for use (in searchResultsTableView) inside this delegate method:

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

Thanks for any corrections!

(I am on iPhone simulator 3.1.2)


@Jessedc

Thanks for your advice. Haven't tried out your code yet.

I solved this headache (before I saw your reply) by setting hidden=YES on the main tableview behind the searchResultsTableView whenever the searchResultsTableView loads, and hidden=NO when the search is over. The main tableview is set with backgroundColor=[UIColor clearColor] on top of an imageview (loaded with the same image as in my original searchResultsTableView code up there).

This new layout is as previously desired :-).


Are trying to display a static background image with the table text scrolling over the top? I think you may have your code a little mixed up (possibly).

Customising a table is usually done in a viewWillAppear method. so this code should go there:

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]; 

Next, in your delegate method searchDisplayController:willShowSearchResultsTableView you are not referring to the tableview object passed in, but you are calling it through the top level (unnecessary perhaps?)

Have a go at moving your table setup code into the viewWillAppear. Let me know if this helps, or if you can provide more information/code.


It seems to me like you're setting the background of your tableview the hard way. I don't know if it's 100% the problem, but you should set your UITableView background like this:

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜