Search code examples
jsonuitableviewyelp

How do you display image from "image_url" in Yelp API?


I now understand how to parse and display JSON data, but one thing eludes me: when I call "image_url" and receive the actual URL, how can I instead display the image that it refers to? ...and yes, I am a novice :)

Thanks!


Solution

  • You can do that like this:

    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:theUrl]]];
    

    where theUrl is the url in string format. Then simply assign the image to your image view: imageView.image = image - presuming you have set up a UIImageView either in your code, as an IBOutlet or as a tagged object in a view.

    NOTE: You may want to have a look at Lazy Table Images to load the image asynchronously.