2010-09-17 124 views
0

我想要一個的tableview細胞的UIImage的設置爲一個絕對的URL,這裏的代碼我已經:如何使用絕對URL設置UIImage?

NSString * imageURL = [[stories objectAtIndex:indexPath.row] objectForKey:@"images"]; 
NSURL *url = [NSURL URLWithString:imageURL]; 
NSData *data = [NSData dataWithContentsOfURL:url]; 
UIImage *img = [[UIImage alloc] initWithData:data]; 
//set image 
cell.imageView.image = img; 

但出於某種原因,這將返回NULL作爲如果提供的URL是無效的。然而我知道這不是這種情況,因爲我可以通過輸入一個URL作爲字符串文字到imageURL指針,我知道代碼[[stories objectAtIndex:indexPath.row] objectForKey:@「images」]返回正確的URL,因爲我打印輸出到日誌,它很好。

是否有任何理由爲什麼會發生這種情況,我顯然沒有在這裏看到?

回答

0

您可以使用absoluteURL方法NSURL和瞧!

NSURL *url = [[NSURL URLWithString:imageURL] absoluteURL];