1

how to get uiimage from a nsurl other than using the method NSData *data = [NSData dataWithContentsOfURL:url]; There is another problem the ui elements are not working while a nsthread is running

Cœur
  • 37,241
  • 25
  • 195
  • 267
iOS Developer
  • 1,723
  • 2
  • 16
  • 47

5 Answers5

1

Personally I tend to use NSOperationQueue.

See

http://developer.apple.com/cocoa/managingconcurrency.html

http://blog.9mmedia.com/?p=549

ader
  • 5,403
  • 1
  • 21
  • 26
1

The AFNetworking library from Gowalla has a nice and easy way to load images in the background. See here

Marko
  • 158
  • 4
0

I like to use ASIHttpRequest. It will be something like this.

ASIHTTPRequest * request = [ASIHTTPRequest requestWithURL:url];

[request setCompletionBlock:^{
    NSData * responseData = [request responseData];
    UIImage * image = [UIImage imageWithData:responseData];
}];
[request setFailedBlock:^{
    NSLog(@"Failed to load image : %@", [request.error localizedDescription]);
}];

[request startAsynchronous];
barley
  • 4,403
  • 25
  • 28
  • I guess the question is to retrieve image without using NSData. – Yama Dec 20 '11 at 10:52
  • Why would you want to avoid NSData? (what's wrong with NSData...?) I thought the question was how to load UIImage without blocking. – barley Dec 20 '11 at 12:25
0

For background image download, you could try

https://github.com/AFNetworking/AFNetworking/
Nick Bull
  • 4,276
  • 1
  • 18
  • 25
0

Go through this link:http://www.markj.net/iphone-asynchronous-table-image/

Download

AsyncImageView.h AsyncImageView.m

add these files to your project and import it in your class

write down these lines wher yu want to add imagesubview:

AsyncImageView *asyncImageView=[[AsyncImageView alloc] initWithFrame:CGRectMake (80, 10, 70,20);]; NSURL *url = [NSURL URLWithString:imageUrl]; [asyncImageView loadImageFromURL:url]; asyncImageView.backgroundColor=[UIColor clearColor]; [myimageView addSubview:asyncImageView]; [asyncImageView release];

you will get

Priyanka Singh
  • 250
  • 2
  • 2