2013-05-25 12 views
0

我正在使用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向特定的細胞是​​

+0

顯然你不會從空字符串中得到很多圖像,如果這就是你要求的。 –

+0

@HotLicks正確。如果從API返回的Image數組爲空,我試圖在ImageView中放置一個Image。你知道我的意思?如果我沒有從他們那裏得到任何回報,我可以在那裏放一張我自己的照片。 – Realinstomp

+0

那麼你的問題是什麼? –

回答

3

你需要檢查你的陣列數和處理,如果它是在訪問任何索引之前小於1。 這是做默認的無圖像圖像URL邏輯的地方。

+0

感謝您的幫助!今天我會嘗試一下 – Realinstomp