Objective c ios- Backgrounds of UITableViewCell all messed up

I am having a problem in tableview, I am setting background of uitableviewcell but when i scroll tableview the background image overlaps the cell's image and text. I dont know the reason. here is the code. kindly help me. Thanks.

NSString *CellIdentifier = [NSString stringWithFormat:@"%d",indexPath.row];

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

UIImage *image = [UIImage imageNamed:@"Workout strip.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.backgroundColor = [UIColor clearColor];
imageView.opaque = NO;
imageView.contentMode = UIViewContentModeBottomLeft;
cell.backgroundView = imageView;
cell.backgroundView.tag = indexPath.row;
[imageView release];
cell.textLabel.text = [exerciseNames objectAtIndex:indexPath.row];
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.imageView.image = [UIImage imageNamed:@"Workout video box.png"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

return cell;


First off get rid of this:

NSString *CellIdentifier = [NSString stringWithFormat:@"%d",indexPath.row];

None of your cells will ever be reused, this is BAD! And most likely a big part of your problem

instead do this:

NSString *CellIdentifier = @"Cell";

Don't set the background view to clear, it's not good for performance. You want subviews to be Opaque unless absolutely necessary.

For reasons that I will never understand the background color of a UITableViewCell can only be set from within this call in your UITableViewDelegate:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
    // do whatever you need to do to your cell here to make it look the way you want

Detailed discussion is in the documentation for UITableViewDelegate.

Need Your Help

Multitenancy Clustered Index Design


I have a multitenancy application and I want a clustered index for the data to support fast range queries.

json schema to validate array of objects with anyOf and oneOf requirements

json validation jsonschema

I am trying to define a json schema to limit the properties of objects conatined in an array.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.