如何自定义不同表格视图单元格中显示的图像?

时间:2011-07-23 02:48:58

标签: objective-c ios image uitableview

我正在尝试将缩略图添加到UITableView

中的单元格中
cell.imageView.image = [UIImage imageNamed: @"TestThumbnail.jpg"];

这就是我在做的事情     (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 方法

但是我想为每个单元格添加不同的缩略图。有可能吗? 如果是这样,我可以将每个图像的名称(例如“thumbnail.png”)添加到.plist并使用它来添加缩略图吗?

谢谢

1 个答案:

答案 0 :(得分:0)

绝对有可能做到这一点。如果您知道要在每行中提前显示哪个图像,则一种方法是构造图像文件名数组。您可以从属性列表中读取该数组,直接在代码中指定它,从服务器下载它......无论您喜欢什么。然后,使用索引路径的row属性为该行的单元格选择图像:

// somewhere in your class declaration...
@property (retain, nonatomic) NSArray *filenames;

// somewhere in your initializer...
self.filenames = [NSArray arrayWithObjects:@"one.jpg", @"two.jpg", @"three.jpg", nil];

// in -tableView:cellForRowAtIndexPath:...
cell.imageView.image = [UIImage imageNamed:[self.filenames objectAtIndex:indexPath.row]];
相关问题