2017-10-21 84 views
1

我从API获取URL图像。我已经将UR图像存储为字符串。在这里我的问题我想显示到旋转木马。我不知道该怎么做。以下是我试过的代码。如何将我的网址图像放入旋转木马?

for(int i=0;i<hotelIMAges.count;i++) 
{ 
    NSDictionary *images=[hotelIMAges objectAtIndex:i]; 
    NSString *Images= [images objectForKey:@"Imagepath"]; 
    [ImageARRAy addObject:Images]; 
} //Here I have stored all the images into string..(https://***.jpg) 

Carousel *carousel = [[Carousel alloc] initWithFrame:CGRectMake(0, 0,300, 262)]; 
[carousel setImages:ImagesARRAy]; 

回答

0

你只需要处理异步作为当前的做法可以是同步请求,并阻止主线程,直到下载完成。

考虑使用SDWebImage和它添加的UIImageView扩展来管理图像下载和显示。它还支持您可以提供的占位符图像,以指示下载正在进行中。

如果您使用任何第三方轮播检查异步方法来显示图像。我相信setImages:方法必须为本地存储在应用程序内的图像。如果您有任何疑问,请告诉我。

---- ---- EDITED

你的传送带是用同步方法来显示哪些块主线程。 您可以使用SDWebImage用于您的目的。 为此,您需要下载SDWebImage以进行图像的异步下载。您可以从下面的链接下载SDWebImage。 你可以用它在你的Carousel.h类作为

#import <SDWebImage/UIImageView+WebCache.h> 

低于行修改您的设置方法。

[imageView sd_setImageWithURL:[NSURL URLWithString:self.images[i]] 
     placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; 

有关详细信息,请参阅SDwebpage的github页面。如果您有任何疑问,请告诉我。 https://github.com/rs/SDWebImage#using-asynchronous-image-downloader-independently

+0

我使用下面的两行轮播代码后所有的图像下载..我写在按钮内...在这里我的问题是我想我的网址图像(https://somestrings.jpg)成(一些string.jpg)格式 – Kavitha

+0

在我使用像这样[carousel setImages:[NSArray arrayWithObjects:@“hotel.jpg”,@“hotel2.jpg”,@“hotel3.jpg”,@“hotel4.jpg”,@ “hotel5.jpg”,无]];现在我得到的格式为 – Kavitha

+0

的响应是你使用任何第三方库Carousel。如果你这样做,请分享我的链接。 – luckyShubhra