views:

36

answers:

2

I have set the background colour of my UITableView to clear so that I can see the UIWindow. But I want to change the image presented (from background.png), depending on my selection. An example would be: If (selection = 'blue') then image = bluesky.png if (selection = 'green') then image = 'greengrass.png

thx, wes

A: 

Instead of making the background clear and putting an image behind it, you can set the tableview's background color using an image

self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"greengrass.png"]];
lukya
The way that I finally got working was to set the delegate window bacgkground independently of the UITableView
Wes
A: 

Just change the background image based on the selection, assuming your controller is UITableViewController or implements the UITableViewDelegate protocol, do something like:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     NSString *imageName = @"default.png";
     switch (indexPath.row) {
       case ...: // fill correct imageName based on selection
     }

     self.myBackgroundImageView.image = [UIImage imageNamed:imageName];
}

Btw - this also assumes you have an IBOutlet or something for your background image.

lwe