Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

How to add a image in tableviewcell?

image title


image title


image title


image title


like this

5 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

The next stage in "Build a Blog Reader App (iPhone)" covers exactly this. :smile:

Until then, you'll need to use the optional image view from one of the default table cell styles. Check out these documents from the Apple Developer site for assistance. The second has some sample code that should help in Listing 5-1:

I got it. Thanks!

UIImage *shot_image = [UIImage imageNamed:[blogPost valueForKey:@"image_url"]]; cell.imageView.image = shot_image;

why the image can't display in the cell?

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

There's a good, succinct answer on StackOverflow that talks about this: http://stackoverflow.com/a/2782491/475217

You tried using the imageNamed: method, which is for images that are local resources to your app. To get an image from the web you need to use the imageWithData: convenience method.

UIImage *shot_image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[blogPost valueForKey:@"image_url"]]]]; cell.imageView.image = shot_image;

I tried this, it works.Thanks a lot! But I don't know why it's very slow and it's hard to slide?