2011-10-01 74 views
0

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

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); 

我初始化的NSMutableArray(appDelegate.categories)和的appdelegate的NSMutableDictionary。

在此先感谢。

+0

如果数据是纯粹的数组/词典数据,只字符串和数字,将其转换成JSON和储存JSON。 –

+0

@DanielRHicks名称和形象是从uiimagepickercontroller所以任何想法? –

+0

你可以通过'NSData * data = UIImagePNGRepresentation(aImage);'将'UIImage'转换成'NSData'。希望有助于! – msgambel

回答

0

从我的理解,你想保存你的图片& retreive他们。您可以使用2种方法之一将图像转换为NSData,其中UIImagePNGRepresentationUIImageJPEGRepresentation取决于图像的类型。然后,您可以保存该数据 -

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. 

HTH,

阿克沙伊