将图像加载到一个单元格 UITableView - xcode

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7930267/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:16:09  来源:igfitidea点击:

Load an image in to one cell UITableView - xcode

iphoneobjective-ciosxcode

提问by TMB87

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

我通过以下方式将 2 个信息数组加载到 UITableView 控件中:

- (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) 将位置的图像作为第一个单元格。

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?

所以就在 locName 之前,我希望 locImage 在那里。如何将图像加载到数组中,然后将其显示在单元格中?

Thanks

谢谢

Tom

汤姆

回答by Jonas Schnelli

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

我建议不要将 UIImage 加载到 NSArray 中。只需将“ImageName”(文件名)作为 NSString 添加到 NSArray 中。

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.

您需要将 NSString 加载到 NSArray arryTableImage 中。

Okay four you?

四个你好吗?