Warrior
Warrior

Reputation: 39374

How to display the image in a cell?

I am new to iphone development.I want to display image in each cell.I am having only the url of the image in a array.please help me out.Thanks.

Upvotes: 1

Views: 966

Answers (2)

Convolution
Convolution

Reputation: 2351

//put this code in cellForRowAtIndexPath.... I'm assuming you have an array of url's that point to images
id urlPath = [yourArray objectAtIndex:indexOfImage];
NSURL *url = [NSURL URLWithString:urlPath];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];


static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}   

//insert an image into your cell
cell.imageView = image;

There is probably a more efficient way to do this, but it's a decent way to get started customizing your tableview cells. ImageView is one of many properties of the UITableViewCell class.

Further reading.... UITableViewCell Class Reference

Upvotes: 4

Oscar Gomez
Oscar Gomez

Reputation: 18488

You should take a look at this apple's sample code, it is great and shows how to implement what you need plus other useful stuff: Advanced Table View Cells

Upvotes: 2

Related Questions