views:

581

answers:

1

I'm doing this to load an image into a tableview cell:

UIImage *image = [UIImage imageNamed:@"myimage.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake( 0, 0, cell.frame.size.width, cell.frame.size.height );
imageView.contentMode = UIViewContentModeScaleToFill;
[cell addSubview:imageView];
[imageView release];

return cell;

However, no image displays as the cell's background. This is in a new navigation app. The above looks just like the steps in Interface Builder when you are using a custom cell. The image is in the app bundle. What am I doing wrong?

+1  A: 

Are you trying to set the cell's background, or just add an image? If you're trying to set its background, you should use the cell.background property.

imageView.frame = cell.bounds;
imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
cell.backgroundView = imageView;

Ben Gottlieb
I'm trying to have the cell background be an image. I mixed in your code but still no image.
4thSpace