Posted By

rabc on 03/15/10


Tagged

image download iphone assyncrhonous


Versions (?)

Who likes this?

6 people have marked this snippet as a favorite

umang_nine
cdnicoll
clearbrian
sb
Tintenklecks
cnathan


Assyncrhonous download


 / Published in: Objective C
 

It was based in Markjnet example here:

http://www.markj.net/iphone-asynchronous-table-image/

  1. // *.h
  2. NSURLConnection* connection;
  3.  
  4. =======
  5.  
  6. // *.m
  7.  
  8. - (void)viewWillAppear:(BOOL)animated {
  9.  
  10. // request the data
  11. NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.img] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
  12. connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
  13.  
  14. }
  15.  
  16. - (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)incrementalData {
  17. if (data==nil) {
  18. data = [[NSMutableData alloc] initWithCapacity:2048];
  19. }
  20. [data appendData:incrementalData];
  21. }
  22.  
  23. - (void)connectionDidFinishLoading:(NSURLConnection*)theConnection {
  24.  
  25. [connection release];
  26. connection=nil;
  27.  
  28. // do the stuff with your downloaded data here
  29.  
  30. }

Report this snippet  

You need to login to post a comment.