Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "MyViewController.h"
- #import "Picture.h"
- #import "ASIHTTPRequest.h"
- @implementation MyViewController
- @synthesize pageNumberLabel, image, myPic, indic;
- // Load the view nib and initialize the pageNumber ivar.
- - (id)initWithPageNumber:(int)page pic:(Picture *)actual_pic {
- if (self = [super initWithNibName:@"MyViewController" bundle:nil]) {
- pageNumber = page;
- myPic = actual_pic;
- }
- return self;
- }
- - (void)dealloc {
- [pageNumberLabel release];
- [image release];
- [super dealloc];
- }
- //Asynchronous image downloading
- - (IBAction)grabURLInBackground:(NSURL *)url
- {
- ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
- [request setDelegate:self];
- [request startAsynchronous];
- }
- - (void)requestFinished:(ASIHTTPRequest *)request
- {
- // Use when fetching binary data
- NSData *responseData = [request responseData];
- NSLog(@"Loaded pic: %d", pageNumber);
- [indic stopAnimating];
- self.image.image = [UIImage imageWithData:responseData];
- }
- - (void)requestFailed:(ASIHTTPRequest *)request
- {
- NSLog(@"it failed");
- //NSError *error = [request error];
- }
- // Set the label and background color when the view has finished loading.
- - (void)viewDidLoad {
- [self grabURLInBackground:myPic.url];
- pageNumberLabel.text = myPic.title;
- pageNumberLabel.numberOfLines = 0;
- pageNumberLabel.frame = CGRectMake(5,5,300,800);
- [pageNumberLabel sizeToFit];
- }
- @end
Add Comment
Please, Sign In to add comment