Adriana
Adriana

Reputation: 806

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 :(

Upvotes: 0

Views: 1988

Answers (3)

spiceIt
spiceIt

Reputation: 16

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.

Upvotes: 0

marzapower
marzapower

Reputation: 5611

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.

Upvotes: 2

TheRonin
TheRonin

Reputation: 1315

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"];

Upvotes: 1

Related Questions