Let's now show a thumbnail image of a restaurant next to its name. In the JSON API call, we also see that we are getting the link for the restaurant image. So, we use this URL to display the image with the restaurant name in the table view.
Update restaurant_controller.rb
as follows:
def tableView(tableView, cellForRowAtIndexPath:indexPath) @reuseIdentifier ||= "CELL_IDENTIFIER" cell = tableView.dequeueReusableCellWithIdentifier(@reuseIdentifier) || begin UITableViewCell.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier:@reuseIdentifier) end cell.textLabel.text = @restaurants[indexPath.row].name cell.imageView.image = UIImage.alloc.initWithData(NSData.alloc.initWithContentsOfURL(NSURL.URLWithString(@restaurants[indexPath.row].thumb_url_image))) cell end
UIImage.alloc.initWithData
initializes and returns the image object with the specified data, and NSData.alloc.initWithContentsOfURL
initializes a newly allocated...