Tom Tom - 11 months ago 68
iOS Question

Load an image in to one cell UITableView - xcode

I have 2 arrays of information that I'm loading in to an UITableView control through the following:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];

if(indexPath.section == 0)

cell.textLabel.text = [arryTableData objectAtIndex:indexPath.row];

cell.textLabel.text = [arryTableActions objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryNone;
return cell;

I want the top array (arryTableData) which is below this to have as the first cell an image of the location.

arryTableData = [[NSArray alloc] initWithObjects:[NSString stringWithFormat:@"%@", locName],
[NSString stringWithFormat:@"%@", locPhone],
@"Address Info",
@"Access Icons",

So just before locName I'd like locImage to be in there. How do I load an image in to the array and then display it in the cell?



Answer Source

I would recommend NOT to load a UIImage into a NSArray. Just add the "ImageName" (filename) into the NSArray as NSString.

When you need to show your image, do this:

UIImage * image = [UIImage imageNamed:[arryTableImage objectAtIndex:indexPath.row]];
cell.imageView.image = image;

You need to load NSString into the NSArray arryTableImage.

Okay four you?