Skip to content

Instantly share code, notes, and snippets.

@raveman
Created August 13, 2012 05:43
Show Gist options
  • Save raveman/3337220 to your computer and use it in GitHub Desktop.
Save raveman/3337220 to your computer and use it in GitHub Desktop.
Downloads in thread and assigning in main thread
-(void)getPhotoWithThread
{
if (self.photoDictionnaire)
{
dispatch_queue_t downloadQueue = dispatch_queue_create("flickr photoDowloader", NULL);
dispatch_async(downloadQueue,
^{
self.photoView.image = [UIImage imageWithData:
[NSDatadataWithContentsOfURL:
[FlickrFetcherurlForPhoto:self.photoDictionnaireformat:FlickrPhotoFormatLarge]]];
dispatch_async(dispatch_get_main_queue(),
^{
self.scrollView.contentSize = self.photoView.image.size;
self.photoView.frame = CGRectMake(0,0, self.photoView.image.size.width,
self.photoView.image.size.height);
self.title = [self.photoDictionnaireobjectForKey:FLICKR_PHOTO_TITLE];
});
});
dispatch_release(downloadQueue);
}
else
{
UIImage *image = [UIImage imageNamed: @"vide.png"];
[self.photoView setImage:image];
}
}
-(void)setPhotoDictionnaire:(NSDictionary *)photoDictionnaire
{
_photoDictionnaire = photoDictionnaire;
[self getPhotoWithThread];
[self.photoView setNeedsDisplay]; // [self.photoView.image setNeedDisplay];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment