简体   繁体   中英

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];

    else
        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",
                            nil];

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?

Thanks

Tom

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM