Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refreshing image #9

Open
serkanb opened this issue Jul 15, 2014 · 4 comments
Open

Refreshing image #9

serkanb opened this issue Jul 15, 2014 · 4 comments

Comments

@serkanb
Copy link

serkanb commented Jul 15, 2014

Hello,
First of all thanks for wonderful control.
I have a problem with refreshing images. My app download images from web server with SDWebImage. It shows a placeholder image until the real one is received. The image is embedded in imageAtIndex method. The problem is the real image is not replaced with placeholder image.

- (void)photoPagesController:(EBPhotoPagesController *)controller
                imageAtIndex:(NSInteger)index
           completionHandler:(void (^)(UIImage *))handler
{
    dispatch_queue_t queue =     dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);     
    dispatch_async(queue, ^{
        MyPhoto *photo = self.photos[index];
        handler(photo.imageView.image);
    });
}

How can I refresh the image? Could you help me please?

@EddyBorja
Copy link
Owner

photo.imageView.image is holding a placeholder image until it downloads the real image from the server, which causes the placeholder to be displayed in the photo gallery instead of the real photo.

I don't know much about SDWebImage, but does it have some kind of way of notifying that it has finished downloading the image from the server?

If not, I'd recommend finding another way of downloading images from the server or modifying SDWebImage. Right now there's no support for refreshing photos in the gallery once you've passed in an image to display.

@serkanb
Copy link
Author

serkanb commented Jul 21, 2014

Thanks Eddy,
I used SDWebImages below method like you said.

    [self.manager cachedImageExistsForURL:photo.url completion:^(BOOL isInCache) { ... }

How can I show activity indicator until image is became ready?

@EddyBorja
Copy link
Owner

There used to be built in support for an activity indicator animating while
waiting for content to appear, but due to a bug it's not working.

Not a very useful answer, but I just haven't had time to fix it with all my
other work going on.

On Monday, July 21, 2014, serkanb notifications@github.com wrote:

Thanks Eddy,
I used SDWebImages below method like you said.

[self.manager cachedImageExistsForURL:photo.url completion:^(BOOL isInCache) { ... }

How can I show activity indicator until image is became ready?


Reply to this email directly or view it on GitHub
#9 (comment)
.

@serkanb
Copy link
Author

serkanb commented Jul 28, 2014

Activity indicator started to run after I had made below changes in EBPhotoViewController and EBImageLoadOperation

in EBPhotoViewController I've made below chances:

    #pragma mark - (Operations)
    @implementation EBPhotoViewController (Operations)

    - (void)operationWillStartLoading:(NSOperation *)operation
    {
        NSAssert(self.activeOperations, @"Must have a pendingOperations set.");
        // I've added below if check
        if ([operation isKindOfClass:[EBImageLoadOperation class]]) {
            [self.activeOperations addObject:operation];
            [self showActivityIndicator];
        }
    }

    - (void)operationDidStopLoading:(NSOperation *)operation
    {
        NSAssert(self.activeOperations, @"Must have a pendingOperations set.");
      // I've removed below assert 
      // NSAssert([self.activeOperations containsObject:operation], @"PendingOperations did not contain given operation.");

        [self.activeOperations removeObject:operation];
     // I've removed below if 
     // if(self.activeOperations.count == 0){
        //I've added below if check
        if ([operation isKindOfClass:[EBImageLoadOperation class]]) {
               [self hideActivityIndicator];
        }
        //}
}

in EBImageLoadOperation I've made below changes

@implementation EBImageLoadOperation

@implementation EBPhotoPagesOperation

- (void)main
{
    @autoreleasepool {
        NSAssert(self.photoPagesController, @"Must have a photo pages controller assigned.");
        NSAssert(self.photoViewController, @"Must have a photo view controller to pass image to");
        NSAssert(self.dataSource,@"Must have a datasource to retrieve image from");

        [self setLoadingFinished:NO];
        [self operationWillStart];
        [self loadData];
        // I've removed below line.
 //       [self operationDidFinish];
    }
}


#pragma mark - Image Loading

@implementation EBImageLoadOperation
- (void)loadData
{

    if([self.dataSource respondsToSelector:@selector(photoPagesController:imageAtIndex:)]){
        [self performSelectorOnMainThread:@selector(loadImageOnMainThread)
                               withObject:nil
                            waitUntilDone:NO];

    } else if ([self.dataSource respondsToSelector:
                @selector(photoPagesController:imageAtIndex:completionHandler:)]){

        [self.dataSource photoPagesController:self.photoPagesController
                                 imageAtIndex:self.photoViewController.photoIndex
                            completionHandler:^(UIImage *image){

            [self.photoViewController performSelectorOnMainThread:@selector(setImage:)
                                                       withObject:image
                                                    waitUntilDone:YES];

           // I've added  below line 
           [self operationDidFinish];
        }];
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants