gpt4 book ai didi

iphone - 如何在 IOS 中从 NSDictionary 获取图像数组

转载 作者:行者123 更新时间:2023-11-29 13:18:48 24 4
gpt4 key购买 nike

我想获取所有具有配方 ID 的图像数组,并想将此图像数组传递给下一个 viewController 但我的问题是我只获取一个图像,我使用 recipeDC 作为实体类,因为所有图像的数组应该我使用另一个实体类或者也可以通过使用相同的类来完成,我该怎么办,我卡住了请帮助我,

-(NSMutableArray *)getAllRecipiesByUserId:(RecipeDC *)recipeid
{
NSMutableArray *dataArray = [[NSMutableArray alloc] init];

NSString *url = [NSString stringWithFormat:@"%@get_all_recipies_by_user_id&user_id=%d",kWSURL,recipeid.user_id];


NSDictionary * returnDict = (NSDictionary *) [self callWebService:url];
if([returnDict objectForKey:@"response"])
{
NSDictionary * returnDictSuccess = (NSDictionary *) [returnDict objectForKey:@"response"];
NSArray *returnedDealArray = [returnDictSuccess objectForKey:@"recipies"];

RecipeDC *recpie = [[RecipeDC alloc] init];
for(NSDictionary *dealDict in returnedDealArray)
{

recpie.recipe_id=[[dealDict objectForKey:@"recipe_id"]intValue ];
recpie.category_id=[[dealDict objectForKey:@"category_id"]intValue ];
recpie.user_id=[[dealDict objectForKey:@"user_id"]intValue ];
recpie.recipe_name = [dealDict objectForKey:@"recipe_name" ];
recpie.recipe_detail = [dealDict objectForKey:@"recipe_detail"];


NSArray *img = [dealDict objectForKey:@"images"];

for(NSDictionary *dealDict in img)
{
recpie.recipie_img_id=[[dealDict objectForKey:@"recipe_images_id"]intValue];
recpie.recipe_id=[[dealDict objectForKey:@"recipe_id"]intValue];
recpie.recipie_img_url=[dealDict objectForKey:@"image_url"];

}
[dataArray addObject:recpie];
NSLog(@"arr count is %u",[dataArray count]);

}
}
return dataArray;

}

最佳答案

你已经完成了

RecipeDC *recpie = [[RecipeDC alloc] init];
for(NSDictionary *dealDict in returnedDealArray)
{

应该是

    for(NSDictionary *dealDict in returnedDealArray)
{
RecipeDC *recpie = [[RecipeDC alloc] init];

在循环中..

已编辑要获取图像数组,您可以保存正在执行的整个数组字典

NSArray *img = [dealDict objectForKey:@"images"];

for(NSDictionary *dealDict in img)
{
recpie.recipie_img_id=[[dealDict objectForKey:@"recipe_images_id"]intValue];
recpie.recipe_id=[[dealDict objectForKey:@"recipe_id"]intValue];
recpie.recipie_img_url=[dealDict objectForKey:@"image_url"];

}

相反,在 RecipeDC 类中声明一个属性为 NSArray *images;只需执行以下操作

recpie.images=[dealDict objectForKey:@"images"];

关于iphone - 如何在 IOS 中从 NSDictionary 获取图像数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14888969/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com