UIImageView inside Custom Table View Cell
I have a customized table view cell which contains 3 labels and an imageView. I'm populating a table view with the table view cells. In the table view implementation, I define what I want to be shown in each table view cell. The labels work fine, but the image doesn't. I'm doing
[[cell subject] setText:subject];
...
[[cell imageView] setImage:[UIImage imageNamed:@"full_path"]];
"subject" is a label and it works fine. But the image isn't appearing in the table view. Any ideas about what I'm missing?
Thanks, Adriana
Problem solved: In the Table View Cell I forgot to add the referencing outlet to the image view开发者_开发百科 :(
I think that the imageView
property of the UITableViewCell object points to an already defined attribute, appropriately handled by the object.
What I usually do is creating a custom cell view through Interface Builder, assign each single component that I want to be able to refer to a different tag (even this can be done in IB). Then in the code you can use this piece of code:
UIImageView *img = (UIImageView *)[cell viewWithTag:yourTag];
img.image = [UIImage imageNamed:@"full_path"];
This way you'll be able to use a custom number of different component, each with a different tag number.
Hope this helps.
When you use :
[UIImage imageNamed:@""];
You don't need to put full path but only file name if he is in your bundle.
[UIImage imageNamed:@"myPict.png"];
If your image is not in your main bundle use (or always if you want):
[UIImage imageWithContentsOfFile:@"full_path"];
I would check the following: * make sure that you init the cell values after the cell is created (viewDidLoad) * if you are using the IB make sure that the image is connected.
精彩评论