iPhone:将NSMutableArray转换为NSData,存储&检索问题

时间:2011-10-01 04:52:06

标签: iphone nsmutablearray nsdata store nsmutabledictionary

我遇到了一个问题,即将NSMutableArray转换为NSData并存储&将该数组检索到rootviewcontroller所以请给我一些想法。这是我正在使用的代码:

appDelegate = (FindNearMeAppDelegate *)[[UIApplication sharedApplication]delegate];

appDelegate.isCategoryCell = TRUE;

appDelegate.isButton = NO;

NSString *categoryStr = categoryName.text;
NSLog(@"Category Name:--->%@",categoryStr);

appDelegate.categoryData = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                 categoryStr, @"name",image ,@"image", nil];

[appDelegate.categories addObject:appDelegate.categoryData];
NSLog(@"Category Data:--->%@",appDelegate.categories);

我在appdelegate初始化nsmutablearray(appDelegate.categories)和nsmutabledictionary。

提前致谢。

1 个答案:

答案 0 :(得分:0)

根据我的理解,您希望保存图像并检索它们。您可以使用以下两种方法之一NSDataUIImagePNGRepresentation将图片转换为UIImageJPEGRepresentation,具体取决于图片的类型。然后,您可以保存此数据 -

NSData* imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:imagePath atomically:YES]; //imagePath is where you want to save it. Most likely it contains the value of the name key in your dictionary.