reloading image from web

Discussion in 'iPhone/iPad Programming' started by pamelaraj, Apr 22, 2009.

  1. macrumors newbie

    Joined:
    Apr 8, 2009
    #1
    #################################

    -(IBAction)touchDownLoad:(id)sender
    {
    NSMutableString *url = [[NSMutableString alloc]init];
    [url appendString:mad:"http://www.beyond2000.co.za/images/2006-4/Large/smal_janene_large.jpg"];

    theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
    cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];
    [url release];
    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    if( theConnection)
    {
    receivedData = [[NSMutableData data] retain];
    lblMessage.text = @"receivedData";
    }

    }

    -(IBAction)cancelView:(id)sender
    {
    [imageDownload autorelease];
    [imageDownload removeFromSuperview];
    }

    - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
    {
    lblMessage.text = @"connection didReceiveResponse";
    [receivedData setLength:0];
    }

    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
    {
    lblMessage.text = @"connection didReceiveData";
    [receivedData appendData:data];
    }

    - (void)connectionDidFinishLoading:(NSURLConnection *)connection
    {
    lblMessage.text = [NSString stringWithFormat:mad:"connectionDidFinishLoading: %@", receivedData];
    // doing something with receivedData
    imageDownload.image = [UIImage imageWithData:receivedData];
    }

    ##############################

    When I run the program, it downloads the image from the specified Url. When I click the "Cancel" button (which implements the "CancelView" method ), it removes the image. But when I click the "download" (which calls the "touchDownLoad" method) button, it just exists out. I want the download and the cancel button to work numerous times and not just once. How could I do that?

    Thanks.
     
  2. thread starter macrumors newbie

    Joined:
    Apr 8, 2009
    #2
    Resolved the issue

    instead of this code:
    ######
    -(IBAction)cancelViewid)sender
    {
    [imageDownload autorelease];
    [imageDownload removeFromSuperview];
    }
    ######

    I used
    #######

    -(IBAction)cancelView:(id)sender
    {
    imageDownload.image = nil;
    }
    #######
     

Share This Page