Guest User

Untitled

a guest
Jul 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. /*!
  2. @method
  3. @abstract downloads images, this is the method that dispatches tasks in the operation queue
  4. */
  5. - (void) loadImage:(id)arg
  6. {
  7. NSLog(@"AsyncImageLoadingViewController::loadImage called");
  8.  
  9. if ((arg == nil) || ([arg isKindOfClass:[NSString class]] == NO)) {
  10. return;
  11. }
  12.  
  13. // create a local autorelease pool since this code runs not on main thread
  14. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  15.  
  16. // fetch the image
  17. NSLog(@"AsyncImageLoadingViewController::loadImage - will download image: %@", arg);
  18. NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:arg]];
  19. UIImage *image = [UIImage imageWithData:data];
  20.  
  21. // update tableview with the downloaded image on main thread
  22. [self performSelectorOnMainThread:@selector(updateTableView:) withObject:[image retain] waitUntilDone:NO];
  23.  
  24. [pool release];
  25. }
Add Comment
Please, Sign In to add comment