Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

pamelaraj

macrumors newbie
Original poster
Apr 8, 2009
6
0
#################################

-(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.
 
Resolved the issue

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

I used
#######

-(IBAction)cancelView:(id)sender
{
imageDownload.image = nil;
}
#######
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.