Reputation: 687
I'm trying to add thumbnails into cells in UITableView
cell.imageView.image = [UIImage imageNamed: @"TestThumbnail.jpg"];
This is what i did in
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
method
However I want to add different thumbnails to each cell. Is it possible to do that? If so, can I add name of each image(eg. "thumbnail.png") to .plist and use that to add thumbnails?
Thank you
Upvotes: 0
Views: 611
Reputation: 124997
It's definitely possible to do that. If you know which image you want to appear in each row ahead of time, one approach would be to construct an array of image file names. You could read that array from a property list, specify it directly in the code, download it from a server... whatever you like. Then, use the row property of the index path to select the image for the cell at that 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]];
Upvotes: 0