tags:

views:

41

answers:

1

I want to create an Iphone application using Grouped Table View. I created the Grouped Table View. My Grouped Table View having the three section. I want to add different images as background for each section in grouped table view.

If i use the following code in each section, the total view displayed in same image.

    NSString *backgroundPath = [[NSBundle mainBundle] pathForResource:@"background" ofType:@"jpg"];

    UIImage *backgroundImage = [UIImage imageWithContentsOfFile:backgroundPath];

    UIColor *backgroundColor = [[UIColor alloc] initWithPatternImage:backgroundImage];

    tableView.backgroundColor = backgroundColor; 

    [backgroundColor release];

If anybody known the solution, please help me.

Thanks.

+1  A: 

Try this:

- (void) tableView: (UITableView *) tableView willDisplayCell: (UITableViewCell *) cell forRowAtIndexPath: (NSIndexPath *) indexPath {
    UIColor * color;

    switch (indexPath.section) {
        case 0:
            color = [UIColor colorWithPatternImage: [UIImage imageNamed: @"...0"]]; break;
        case 1:
            color = [UIColor colorWithPatternImage: [UIImage imageNamed: @"...1"]]; break;
        case 2:
            color = [UIColor colorWithPatternImage: [UIImage imageNamed: @"...2"]]; break;
        default:
            color = [UIColor colorWithPatternImage: [UIImage imageNamed: @"..."]]; break;
            break;
    }

    cell.backgroundColor = color;
}

Replace ... and ...X with the images you want to use. Add more or remove some cases to achieve the right number of sections.

Alexsander Akers
Thanks for your answer. It is working well. Thanks.
Velmurugan
Okay. After I read your answer, I wasn't sure if you wanted to change the cell's background or the table's background, but I'm glad it worked out for you.
Alexsander Akers