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

Completion Block should contain the url for downloadWithURL #722

Closed
ilushka85 opened this issue May 21, 2014 · 12 comments
Closed

Completion Block should contain the url for downloadWithURL #722

ilushka85 opened this issue May 21, 2014 · 12 comments
Milestone

Comments

@ilushka85
Copy link

The current completion block looks like this:

completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished)

It really should pass back the original URL. This is neccessary when using the sdwebimagedownloader in a reusable cell. Basically since a cell is reused and completion of image download is async the download of a different image finishes when we are already loading a next one or loaded next image from cache there by replacing the image we should display. If the url were passed here we could check against the original url to see if we should use(display) this image that finished.

@bpoplauschi
Copy link
Member

There is a pull request with this #759. But even without that, you can retain the url in a UITableViewCell property and compare it with the one you used for the request.

@bpoplauschi bpoplauschi added this to the 3.7.0 milestone Jun 17, 2014
@ilushka85
Copy link
Author

Yes this is my push request to fix this issue. You cannot compare it to the url even if its retained in the cell since the completion happens asynchronously ... You need the url in the completion block to compare against the retained url in the uitableviewcell to see if the image should be set or not.

@bpoplauschi
Copy link
Member

I think you can check it, since the issue is the cell that started the request might get reused before the response arrives. I would do something like

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   ...
   cell.imageUrl = url;
   __weak typeof(cell)weakCell = cell;
   ...
   [cell.customImageView setImageWithURL:url completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
      __strong __typeof(weakCell)strongCell = weakCell;
      if ([strongCell.imageUrl isEqual:url]) {
         strongCell.customImageView.image = image;
      }
   }
}

@ilushka85
Copy link
Author

Without testing this it may work.... but its a total hack / workaround for something that truly makes sense to be in the completion block.

@bpoplauschi
Copy link
Member

I was giving you an option until that gets merged in.

@ilushka85
Copy link
Author

@bpoplauschi Thank you but since i created the pull request its merged on our end so we are ok for now. I just wanted to ensure this gets included some time in the future.

@bpoplauschi
Copy link
Member

👍

@ilushka85
Copy link
Author

@bpoplauschi any idea on timeframe on the merge? I know its a breaking change so just curious.

@bpoplauschi
Copy link
Member

It will probably get included in the next version. If we can't find a backwards compatible way, we might need to bump to version 4.x

@ilushka85
Copy link
Author

What about if i sent a push update that maintains backwards compatibility by creating some stub methods to reference the old completion blocks? That way you can call with new one or old one.

@bpoplauschi
Copy link
Member

Go ahead and try it. We will need a way to know which completion blocks to call and with how many parameters.

@bpoplauschi
Copy link
Member

Fixed by #770

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