简体   繁体   中英

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

我将检查以下内容:*确保在创建单元格后初始化单元格值(viewDidLoad)*如果使用的是IB,请确保已连接图像。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM