I have a UITableViewwhich displays cells with images. On the cellForRowAtIndexPath method I launch a connection to fetch the image. I want to keep track of what images have been already requested in order to avoid requesting the same image multiple times.
I set up a method like this
+(void) setImageFromURL:(NSURL*) url fromImage:(UIImage*) srcImage to:(UIImageView*) dstImage wasRequested:(BOOL*) requested;
and call it like this
[Utils setImageFromURL:event.thumbURL fromImage:event.thumbImage to:cell.image wasRequested:event.thumbRequested];
where event.thumbRequested is a BOOL property. The method look like this
+(void) setImageFromURL:(NSURL*) url fromImage:(UIImage*) srcImage to:(UIImageView*) dstImage wasRequested:(BOOL*) requested{
if (srcImage != nil) {
dstImage.image = srcImage;
} else if (!requested) {
requested = YES;
@try {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData * data = [[NSData alloc] initWithContentsOfURL: url];
if ( data == nil )
return;
dispatch_async(dispatch_get_main_queue(), ^{
__block UIImage* srcImage = [UIImage imageWithData: data];
dstImage.image = srcImage;
});
[data release];
});
}
@catch (NSException *exception) {
NSLog(exception.debugDescription);
}
}
}
My problem is the BOOL is not changing due to the pass by value behavior in Objective-C. Can anyone recommend a way for being able to update the BOOL in the event object from inside the mehod?
The line:
needs to be:
The check is just incase
nilwas passed in forrequested.Edit: And the call should be: