How to put my url images into carousel?

81 Views Asked by At

I am getting URL images from API. I have stored the UR images into string. Here my problem I want to display that into carousel. I don't know how to do this. Below is my code that I have tried.

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];
1

There are 1 best solutions below

5
luckyShubhra On

You just need to process asynchronously as your current approach can be a synchronous request and blocks the main thread until that download is complete.

Consider using SDWebImage and the UIImageView extension it adds to manage the image download and display. It also supports a placeholder image that you can supply to indicate that the download is in progress.

If your using any third party carousel check for asynchronous methods to display the images.I believe setImages: method must be for images that are stored locally inside app. Do let me know if you have any queries.

----EDITED----

Your Carousel is using synchronous method to display which blocks the main thread. You can use SDWebImage for your purpose. For this you need to download SDWebImage for asynchronous downloading of image. You can download SDWebImage from link below. You can use it in your Carousel.h class as

#import <SDWebImage/UIImageView+WebCache.h>

modify your setup method with below line.

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

For details refer github page of SDwebpage. DO let me know if you have any queries. https://github.com/rs/SDWebImage#using-asynchronous-image-downloader-independently