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.
+3
A:
//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
Convolution
2010-02-08 21:24:49
This is workable, but it's best not to load images from the network on the main thread (if from disk it's generally okay)
rpetrich
2010-02-09 08:46:32
Thanks it works fine......
Warrior
2010-02-09 11:55:41
+2
A:
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
OscarMk
2010-02-08 21:36:04
i am having the url of the image in a string array, the above example has all images in the resource.
Warrior
2010-02-09 08:36:59