Reputation: 604
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).
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
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