_pageImages是nsmutableArry我存儲圖像的URL。NSData到uiimage返回null
_pageImages = [[NSMutableArray alloc]initWithObjects:@"https://api.url2png.com/v3/P4DE5D1C99D8EF/7bbb6e0d1b74fb0ae1d4f18b06320096/400x400/abc.com",@"https://api.url2png.com/v3/P4DE5D1C99D8EF/7bbb6e0d1b74fb0ae1d4f18b06320096/400x400/abc.com", nil];
想要在uiimageview中顯示此URL圖像。
NSURL *url = [NSURL URLWithString:[_pageImages objectAtIndex:i]];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
UIImage *tmpImage = [UIImage imageWithData:data];
_backgroundImageView.frame = CGRectMake(0 ,10, 320, 320);
_backgroundImageView.image = tmpImage;
[self.view addSubview:_backgroundImageView];
我看到了很多例子,但我不能得到正確的解決方案。新的發展。幫助我..
您是否檢查過您的數據不是零?因爲也許你只是忘記禁用目標域名的應用傳輸安全 (當我嘗試https://api.url2png.com/v3/P4DE5D1C99D8EF/7bbb6e0d1b74fb0ae1d4f18b06320096/400x400/abc.com我自己,我在瀏覽器中出現錯誤...) – CZ54
是的如何使用返回NSError對象的方法(例如'initWithContentsOfURL:options:error:')。 – trojanfoe
你可以在這裏找到http://stackoverflow.com/questions/30096806/load-uiimage-from-url-in-ios –