1

我想获取具有配方 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;

}
4

1 回答 1

1

你已经完成了

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"];
于 2013-02-15T05:49:13.290 回答