views:

51

answers:

1

Hi, I'm trying to place a UIImageView in a UITableViewCell.

I create a special view called ProductView. In that view, I have several components, one of them being a UIImageView. I set this ProductView as content view of the UITableViewCell. Everything is drawn properly except the UIImageView. UIImageView gets scaled meaninglessly. It's height gets twice the height of the table cell size.

I've spent hours trying to solve this problem. I've set the frame of UIImageView manually, I've called drawRect method of UIImage in UIImageView, neither of them worked.

I'm thinking of replacing UITableView with a UIScrollView if I can't find a solution. Does anyone know how to solve this problem?

A: 

Use the Custom cells, and place all the UI component inside that cell, (including the UIImageView), and in cellForRowAtIndexPath method, set the image like following:

[cell.imgView setContentMode:UIViewContentModeScaleAspectFit];
[cell.imgView setFrame:CGRectMake(cell.imgView.frame.origin.x, cell.imgView.frame.origin.y, 120, 79)];      
[cell.imgView setImage:[UIImage imageNamed:@"image.png"]];          

And if you need to know how to use custom cells, follow this tutorial :

iPhone Programming Tutorial: Part 6: Creating custom UITableViewCell Using Interface Builder [UITableView]

Hope this helps you...

Ansari
Thanks for you answer. Unfortunately I didn't have the time to try your solution. I solved the problem by using a UIScrollView instead of UITableView. I will keep in mind your advice in next time.
Behlül