Advertisement
Guest User

Untitled

a guest
Oct 4th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. NSURL *url = [NSURL URLWithString:@"http://example.com/image.jpg"];
  2. NSData *data = [NSData dataWithContentsOfURL:url];
  3. UIImage *img = [[[UIImage alloc] initWithData:data] autorelease];
  4.  
  5. - (void)connectionDidFinishLoading:(NSURLConnection *)connection
  6. {
  7. if (requestData)
  8. {
  9. self.image = [[[UIImage alloc] initWithData:requestData] autorelease];
  10. }
  11. }
  12.  
  13. [self performSelectorInBackground:@selector(loadImage) withObject:nil];
  14.  
  15. - (void)loadImage
  16. {
  17. NSURL * url = [NSURL URLWithString:@"http://.../....jpg"];
  18. NSData * data = [NSData dataWithContentsOfURL:url];
  19. UIImage * image = [UIImage imageWithData:data];
  20. if (image)
  21. {
  22. // Success use the image
  23. ...
  24. }
  25. else
  26. {
  27. // Failed (load an error image?)
  28. ...
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement