我正在使用RestKit從Web服務API中提取數據,並且當針對「Image」的空數組的API響應時,UITableView
崩潰。TableView崩潰如果空陣列,如何解決?
我想知道如果「if語句」最好能解決問題嗎?
cellForRowAtIndexPath
,當有一個圖像陣列,其完美的作品:
Images *imageLocal = [apiResponseLocal.images objectAtIndex:0];
NSString *imageURL = [NSString stringWithFormat:@"%@", imageLocal.url];
我不爲「if語句」
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"]];
}
我不知道,如果工作最好的猜測我正在試圖用「if語句」來解決這個問題,或者說這個實際陳述可能是什麼。任何幫助將非常感激!
編輯: 錯誤&崩潰,我得到的時候沒有在NSArray
沒有圖像,我嘗試滾動的TableView向特定的細胞是
顯然你不會從空字符串中得到很多圖像,如果這就是你要求的。 –
@HotLicks正確。如果從API返回的Image數組爲空,我試圖在ImageView中放置一個Image。你知道我的意思?如果我沒有從他們那裏得到任何回報,我可以在那裏放一張我自己的照片。 – Realinstomp
那麼你的問題是什麼? –