Adding a dynamic image to UITable View Cell
Posted
by Graeme
on Stack Overflow
See other posts from Stack Overflow
or by Graeme
Published on 2010-04-23T08:04:19Z
Indexed on
2010/04/23
10:33 UTC
Read the original article
Hit count: 413
Hi,
I have a table in which I want a dynamic image to load in at the left-hand side. The table needs to use an IF statement to select the appropriate image from the "Resources" folder, and needs to be based upon [dog types].
The [dog types] is extracted from an RSS feed, and so the image in the table cell needs to match the each cell's [dog types] tag.
Update: See code below for what I'm looking to do (only below it's for earthquakes, for me its pictures of dogs).
I suspect I need to use - (UIImage *)imageForTypes:(NSString *)types { to do such a thing.
Thanks.
Updated code: This is for Apple's Earthquake sample but does exactly what I need to do. It matches images to the severity (2.0, 3.0, 4.0, 5.0 etc.) of every earthquake to the magnitude.
- (UIImage *)imageForMagnitude:(CGFloat)magnitude {
if (magnitude >= 5.0) {
return [UIImage imageNamed:@"5.0.png"];
}
if (magnitude >= 4.0) {
return [UIImage imageNamed:@"4.0.png"];
}
if (magnitude >= 3.0) {
return [UIImage imageNamed:@"3.0.png"];
}
if (magnitude >= 2.0) {
return [UIImage imageNamed:@"2.0.png"];
}
return nil;
}
and under - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
magnitudeImage.image = [self imageForMagnitude:earthquake.magnitude];
© Stack Overflow or respective owner