alexiscreuzot / KASlideShow

Ultra-basic slideshow for iOS (ARC only).
MIT License
206 stars 61 forks source link

NSURL images aren't showing automatically #41

Closed anuchandra closed 8 years ago

anuchandra commented 8 years ago

I have a horizontal scrolling image control (see code below). The first image loads very quickly. The second image also loads quickly. Typically, when I scroll to the third or fourth or fifth image, I get a blank white image and it stays blank. If I swipe left or right, and then swipe back, the image appears. The images aren't too big - 700x700px. I'm guessing the image gets downloaded fine in the background but isn't being shown when the download completes. Am I doing something wrong or is this an issue that could be investigated?

- (void)viewDidLoad 
{
    [super viewDidLoad];
    PageControl.currentPage = 0;
    PageControl.numberOfPages = 1+[add_image_list count];

    if (add_image_list != nil) {
    _datasource = [@[[NSURL URLWithString:imagelink],
                 [NSURL URLWithString:add_image_list[0]],
                 [NSURL URLWithString:add_image_list[1]],
                 [NSURL URLWithString:add_image_list[2]],
                 [NSURL URLWithString:add_image_list[3]],
                 [NSURL URLWithString:add_image_list[4]]
                 ]
               mutableCopy];
    } else {
        _datasource = [@[[NSURL URLWithString:imagelink]
                     ]
                   mutableCopy];
    }
    _slideshow.datasource = self;
    _slideshow.delegate = self;
    [_slideshow setDelay:1]; // Delay between transitions
    [_slideshow setTransitionDuration:.5]; // Transition duration
    [_slideshow setTransitionType:KASlideShowTransitionSlideHorizontal];
    [_slideshow setImagesContentMode:UIViewContentModeScaleAspectFill];
    [_slideshow addGesture:KASlideShowGestureSwipe];
}
- (NSObject *)slideShow:(KASlideShow *)slideShow objectAtIndex:(NSUInteger)index
{
    return _datasource[index];
}

- (NSUInteger)slideShowImagesNumber:(KASlideShow *)slideShow
{
    return _datasource.count;
}
- (void) slideShowWillShowNext:(KASlideShow *)slideShow
{
    NSLog(@"slideShowWillShowNext, index : %@",@(slideShow.currentIndex));
}

- (void) slideShowDidSwipeLeft:(KASlideShow *) slideShow;
{
    [_slideshow next];
    if (PageControl.currentPage<PageControl.numberOfPages-1)
        PageControl.currentPage = PageControl.currentPage+1;
    else
        PageControl.currentPage = 0;   
}
- (void) slideShowDidSwipeRight:(KASlideShow *) slideShow;
{
    [_slideshow previous];
    if (PageControl.currentPage == 0)
        PageControl.currentPage = PageControl.numberOfPages-1;
    else
        PageControl.currentPage = PageControl.currentPage-1;
}
alexiscreuzot commented 8 years ago

This is linked to the lazy loading of images. You can solve this by prefetching your images with SDWebImagePrefetcher. You can find an example here : http://stackoverflow.com/questions/18509624/sdwebimage-eager-load-images

anuchandra commented 8 years ago

Thanks, that worked.