vamsi575kg
vamsi575kg

Reputation: 604

customize tableview background using tableView willDisplayCell: delegate method

I want to customize tableview background with my own images i am using the fallowing code to customize cell background view

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

    NSInteger rowCount = [self tableView:[self tableView] numberOfRowsInSection:0];
    NSInteger rowIndex = indexPath.row;
    UIImage *background = nil;

    if (rowIndex == 0) {
        background = [UIImage imageNamed:@"TableTopBackground.png"];
    } else if (rowIndex == rowCount - 1) {
        background = [UIImage imageNamed:@"TableBottomBackground.png"];
    } else {
        background = [UIImage imageNamed:@"TableMiddleBackground.png"];
    }

    [cell setBackgroundView:[[UIImageView alloc]initWithImage:background]];

}

my problem is the bottom cell images and middle cell images are interchanged when i run in ios5 (image 1) but in ios6 it was fine(image 2).

ios 5 image

ios 6 image

but setting the background color it was working fine in both ios5 and ios 6. can any one help me in solving it.

writing the code in cellForRowatindexpath its working but why does it not working in willdisplaycell.

Thank you

Upvotes: 2

Views: 1362

Answers (1)

iPatel
iPatel

Reputation: 47099

Put image in cellForRowAtIndexPath method and add with

    cell.backgroundView.backgroundColor = [UIColor colorWithPatternImage:image];

This code write between

if(cell == nil)
 {
 }

Upvotes: 1

Related Questions