如何在Array中使用addObject?

时间:2014-05-25 18:09:27

标签: ios objective-c arrays nsmutablearray

我有一个NSMutableArray * arrayFavorite

在日志中我看到了

{      name1 = 6;
       name2 = "Paolo Rossi\nIt\U00e1lia";
       name3 = "cartaz-1982.jpg";
       photo = "copa8.jpg";
       name4 = 24;
   },
    {
       name1 = 6;
       name2 = "Oleg Salenko\nR\U00fassia";
       name3 = "cartaz-1994.jpg";
       photo = "copa5.jpg";
       name4 = 24;
   },

我需要变性这个

self.tableItems = @[[UIImage imageNamed:@"photo1.jpg"],
                       [UIImage imageNamed:@"photo2.jpg"],
                       [UIImage imageNamed:@"photo3.jpg"]];

从我的*数组收藏夹获取动态信息照片名称

我该怎么做?

由于

2 个答案:

答案 0 :(得分:0)

您需要做的只是枚举字典数组并使用photo keyValue到+imageNamed:...创建图像。

NSArray *imageInfoDicts = ...;
NSMutableArray *images = [NSMutableArray array];
[imageInfoDicts enumerateObjectsUsingBlock:^(NSDictionary *dictionary, NSUInteger idx, BOOL *stop) {
    [images addObject[UIImage imageNamed:dictionary[@"photo"]]];
}];
NSLog(@"%@", images);

答案 1 :(得分:0)

由于您在tableView中显示此数据,您应该抓取特定行的数据,然后在该时间点获取图像,以避免一次将所有图像加载到内存中。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<identifier> forIndexPath:indexPath];

  NSDictionary *item = self.items[indexPath.row];

  cell.imageView.image = [UIImage imageNamed:item[@"photo"]];

  return cell;
}
相关问题