Is there a better way to load images dynamically into the tableviewcell for different rows other than using the if statements? What if I have a lot of cells. does that mean I would have to write a lot of if statements? Also is there a way to retrieve an image from core data and use it as a image for tableview cell? thanks in advance.
- (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;
}
edit: what if it isn’t about magnitude? for example a list of products or like the app store on the iphones. how did they manage to generate different images for the different apps on the table? are they using a table or is there a better way to do this?
Round down the magnitude using the
floorffunction from<math.h>Then use the
MINandMAXmacros to protect the real value from going above 5 or below 2.Update: I think this is what you’re looking for: in
-tableView:cellForRowAtIndexPath:, use the providedNSIndexPathto fetch the relevant image: