UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.example.com/image.png"]]];
In the above line of code, NSURL URLWithString:
is to use with file system URL like already downloaded image in your temp directory or plist file etc. Since you have passed a http
URL it makes synchronous request blocking your thread until it finishes downloading image data. And if you are doing this on main thread then UI doesn't respond to touches until image gets downloaded.
Change it to make asynchronous call, i.e., download example.com/image.png asynchronously. You may refer to ASIHTTPRequest
instance method startAsynchronous
and then pass downloaded data to UIImage imageWithData:
To learn more about asynchronous network requests, watch session 208 WWDC 2010 Network Apps for iPhone OS Part-2