I'm using RestKit to pull data from a web service API, and when the API response with an empty array for "Image", the UITableView crashes.
I was wondering if an "if statement" would be best to solve the problem?
cellForRowAtIndexPath, which works perfectly when there is an Image Array:
Images *imageLocal = [apiResponseLocal.images objectAtIndex:0];
NSString *imageURL = [NSString stringWithFormat:@"%@", imageLocal.url];
My best guess that doesn't work for the "if statement"
if ([imageURL isEqualToString:@""])
{
[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://staticimage.com/to/use/when/no/image/from/api"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
}
else
{
[cell.imageView setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", imageURL]] placeholderImage:[UIImage imageNamed:@"placeholder"]];
}
I'm not sure if I'm on the right trail trying to solve with an "if statement", or what that actual statement might be. Any help would be much appreciated!
EDIT:
Error & Crash I get when there is no image in the NSArray and I try scrolling the TableView toward that particular cell is "_NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array"