Created
August 13, 2012 05:43
-
-
Save raveman/3337220 to your computer and use it in GitHub Desktop.
Downloads in thread and assigning in main thread
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -(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