Ios 如何在数组中使用addObject?
我有一个NSMutableArray*arrayFavorite 在日志中我看到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
{ 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
?