[英]how to get Image Array from NSDictionary in IOS
i want to get array of all images with recipe id and want to pass this array of images to next viewController but my problem is that i am getting only one image,i used recipeDC as entity class, for array of all images should i use another entity class or it can also be done by using same class, what should i do, im stuck please help me, 我想获取所有具有配方ID的图像的数组,并希望将此图像数组传递给下一个viewController,但是我的问题是我仅获取一个图像,我将配方DC用作实体类,对于所有图像的数组我应该使用另一个实体类,或者也可以使用相同的类来完成,该怎么办,即时通讯卡住了,请帮助我,
-(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;
}
You have done 你做完了
RecipeDC *recpie = [[RecipeDC alloc] init];
for(NSDictionary *dealDict in returnedDealArray)
{
It should be 它应该是
for(NSDictionary *dealDict in returnedDealArray)
{
RecipeDC *recpie = [[RecipeDC alloc] init];
Inside the loop.. 循环内
Edited To get array of images you can save the whole dictionary of array you are doing 编辑要获取图像数组,可以保存正在执行的整个数组字典
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"];
}
Instead, declare a property in RecipeDC class as NSArray *images; 而是在RecipeDC类中将属性声明为NSArray * images;。 and just do the following 然后执行以下操作
recpie.images=[dealDict objectForKey:@"images"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.