How to display the image in a cell?
-
19-09-2019 - |
Question
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.
Solution
//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
OTHER TIPS
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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow