Guest User

Untitled

a guest
Feb 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #import "MyViewController.h"
  3. #import "Picture.h"
  4. #import "ASIHTTPRequest.h"
  5.  
  6.  
  7. @implementation MyViewController
  8.  
  9. @synthesize pageNumberLabel, image, myPic, indic;
  10.  
  11.  
  12. // Load the view nib and initialize the pageNumber ivar.
  13. - (id)initWithPageNumber:(int)page pic:(Picture *)actual_pic {
  14.     if (self = [super initWithNibName:@"MyViewController" bundle:nil]) {
  15.         pageNumber = page;
  16.         myPic = actual_pic;
  17.     }
  18.     return self;
  19. }
  20.  
  21. - (void)dealloc {
  22.     [pageNumberLabel release];
  23.     [image release];
  24.     [super dealloc];
  25. }
  26.  
  27. //Asynchronous image downloading
  28. - (IBAction)grabURLInBackground:(NSURL *)url
  29. {
  30.     ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
  31.     [request setDelegate:self];
  32.     [request startAsynchronous];
  33.    
  34. }
  35.  
  36. - (void)requestFinished:(ASIHTTPRequest *)request
  37. {
  38.     // Use when fetching binary data
  39.     NSData *responseData = [request responseData];
  40.     NSLog(@"Loaded pic: %d", pageNumber);
  41.     [indic stopAnimating];
  42.     self.image.image = [UIImage imageWithData:responseData];
  43. }
  44.  
  45. - (void)requestFailed:(ASIHTTPRequest *)request
  46. {
  47.     NSLog(@"it failed");
  48.    
  49.     //NSError *error = [request error];
  50. }
  51.  
  52. // Set the label and background color when the view has finished loading.
  53. - (void)viewDidLoad {
  54.     [self grabURLInBackground:myPic.url];
  55.    
  56.     pageNumberLabel.text = myPic.title;
  57.     pageNumberLabel.numberOfLines = 0;
  58.     pageNumberLabel.frame = CGRectMake(5,5,300,800);
  59.     [pageNumberLabel sizeToFit];
  60. }
  61.  
  62. @end
Add Comment
Please, Sign In to add comment