Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在数组中使用addObject?_Ios_Objective C_Arrays_Nsmutablearray - Fatal编程技术网

Ios 如何在数组中使用addObject?

Ios 如何在数组中使用addObject?,ios,objective-c,arrays,nsmutablearray,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\U00fa

我有一个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"]];
用于从my*array Favorite获取动态信息照片名称

我该怎么做


谢谢

您只需通过字典数组进行枚举,并通过
+imageNamed:…
使用
photo
keyValue创建一个图像

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

因为看起来您是在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;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath;
{
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:forIndexPath:indexPath];
NSDictionary*item=self.items[indexPath.row];
cell.imageView.image=[UIImage-imagename:item[@“photo”];
返回单元;
}

是否询问如何从数组
arrayFavorite
中获取值
photo
,然后使用该值填充
+(UIImage*)imageNamed:(NSString*)name