2015-06-02 32 views
-1

我正在通過xml圖像網址到imageview.image然後我使用datawithcontentsofurl:optionserror像然後我得到這個錯誤。原因: - [_ NSPlaceholderData initWithContentsOfURL:選項:錯誤:]:無URL參數'

的代碼是:

NSError *error=nil; 
imageview.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:sharedDelegate.imagObj] options:NSDataReadingUncached error:&error]]; 

if (error) { 
    NSLog(@"%@",[error localizedDescription]); 
} 
else{ 
    NSLog(@"loading successfully"); 
} 

一些圖像得到上述錯誤和一些圖像成功加載。

+0

'sharedDelegate.imagObj'不是有效的URL。它的價值是什麼? – rmaddy

+0

in shared delegate.imageobj contains http://www.cinejosh.com/telugu/newsimg/mahesh babu-kora-1433152437-1.jpg這是字符串,因爲我們可以從xml圖像url中獲取數組在tableview didselectrow在indexpath我們可以在字符串中找到這個網址,所以我使用nsurl urlwithstring方法發送圖像,並且圖像的一些傳遞通過 –

+0

這不是一個有效的URL。它沒有計劃。您需要添加'http://'或其他適當的方案。 – rmaddy

回答

0

答案是在URL之間有空格是我們需要添加字符串的問題stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding方法我刪除了錯誤。

NSString *spaceStrObj=[sharedDelegate.imagObj stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 

NSError *error=nil; 
imageview.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:spaceStrObj] options:NSDataReadingUncached error:&error]]; 

if (error) { 
    NSLog(@"%@",[error localizedDescription]); 
} 
else{ 
    NSLog(@"loading successfully"); 
} 
相關問題