2011-10-01 45 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,

阿克沙伊