【问题标题】:How to hold an image for every array如何为每个数组保存一个图像
【发布时间】:2012-08-03 08:27:12
【问题描述】:

我正在尝试为 UITabelView 中的每个数组设置图像。如何为照片库中的每个数组设置图像?所以我可以在 UITableView 的单元格中查看。

希望对我有帮助这是我的简单代码Download

从现在开始谢谢。

【问题讨论】:

    标签: ios xcode arrays uitableview uiimageview


    【解决方案1】:

    你可以这样做:

    NSArray *photos = [[NSArray arrayWithObjects:   
                            [UIImage imageNamed:@"1.png"],
                            [UIImage imageNamed:@"2.png"],
                            [UIImage imageNamed:@"3.png"],
                            [UIImage imageNamed:@"4.png"],
                            nil] retain]; // Arrange images in the same order your table data is arranged.
    

    现在,在cellForRowAtIndexPath: 方法中:

    cell.imageView.image = [photos objectAtIndex:indexPath.row];
    

    【讨论】:

    • 感谢 OhhMee,但用户只会从库中选择一张图片。我可能误会了。
    【解决方案2】:

    首先,您是指每张图片吗?您可以使用一个填充有图像的数组来执行此操作。

    您可以在表格视图cellForRowAtIndexPath 方法中执行此操作,通过告诉表格视图其单元格图像属性将填充单元格索引处的数组中的对象,例如:

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

    【讨论】:

    • 感谢 NSPostWhendle,我正在尝试为从数组推送的 UITableView 中的每个用户放置一张图片。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-21
    • 1970-01-01
    • 2015-04-18
    相关资源
    最近更新 更多