I have a table view with some 'n' number of cells.My issue is with background image for cells!
I am already aware of the fact that apple documentation of UITableViewCell specifically says:
Note: If you want to change the background color of a cell (by setting the background color of a cell via the backgroundColor property declared by UIView) you must do it in the tableView:willDisplayCell:forRowAtIndexPath: method of the delegate and not in tableView:cellForRowAtIndexPath: of the data source.
The above description can also be seen here
But my concern is not with changing the color of the cell,rather it is with setting the background image for a cell.As we know we can make use of background color property to set the background image i.e.:
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellIdentifier] autorelease];
cell.backgroundColor = [[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"buttonbg.png"]];
}
But using background color for setting background image to a table view cell isn't working and when I am trying to change the image but not color,why doesn't the above method/property work in datasource method(cell for row at index path)
Also to my surprise I found out that using an image view and setting the view as background view for cell works perfect and the same is suggested in this link by Mr.Ammy Worral. i.e.:
UIImage *cellImage = [UIImage imageNamed:kCellImage];
UIImageView *cellImageView = [[UIImageView alloc]initWithImage:cellImage];
[cell setBackgroundView:cellImageView];
But my doubt is why doesn't the background image work with background color method of cell!
Need some clarification on this!
Thanks all in advance :)