Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. // Create an operation without any work to do
  2. downloadImageOperation = [NSBlockOperation new];
  3.  
  4. // Make a weak reference to the operation. This is used to check if the operation
  5. // has been cancelled from within the block
  6. __weak NSBlockOperation* operation = downloadImageOperation;
  7.  
  8.  
  9. // Give the operation some work to do
  10. [downloadImageOperation addExecutionBlock: ^() {
  11. // Download the image
  12. NSData *data = [NSData dataWithContentsOfURL:[newsimages objectAtIndex:indexPath.row]];;
  13. UIImage *image = [[UIImage alloc] initWithData:data];
  14. NSLog(@"%@",image);
  15. // Make sure the operation was not cancelled whilst the download was in progress
  16. if (operation.isCancelled) {
  17. return;
  18. NSLog(@"gestopt");
  19. }
  20. if (image != nil) {
  21.  
  22. NSData* imageData = UIImagePNGRepresentation(image);
  23.  
  24. [fileManager createFileAtPath:path contents:imageData attributes:nil];
  25. cell.imageView.image = image;
  26. cell.imageView.layer.masksToBounds = YES;
  27. cell.imageView.layer.cornerRadius = 15.0;
  28.  
  29. }
  30.  
  31. // Do something with the image
  32. }];
  33.  
  34. // Schedule the download by adding the download operation to the queue
  35. [queuee addOperation:downloadImageOperation];
  36.  
  37. -(void)viewDidDisappear:(BOOL)animated {
  38. [downloadImageOperation cancel];
  39. }
  40.  
  41. 2012-09-12 21:32:31.869 App[1631:1a07] <UIImage: 0x3965b0>
  42. 2012-09-12 21:32:32.508 App[1631:1907] <UIImage: 0x180d40>
  43. 2012-09-12 21:32:32.620 App[1631:707] view dissappear!
  44. 2012-09-12 21:32:33.089 App[1631:3a03] <UIImage: 0x3a4380>
  45. 2012-09-12 21:32:33.329 App[1631:5a03] <UIImage: 0x198720>
  46.  
  47. NSData *data = [NSData dataWithContentsOfURL:[newsimages objectAtIndex:indexPath.row]];;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement