Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 将NSDictionary与NSMutableArray一起保存为NSUserDefaults的值_Iphone_Ios_Ipad_Ios5 - Fatal编程技术网

Iphone 将NSDictionary与NSMutableArray一起保存为NSUserDefaults的值

Iphone 将NSDictionary与NSMutableArray一起保存为NSUserDefaults的值,iphone,ios,ipad,ios5,Iphone,Ios,Ipad,Ios5,我将UIImage存储在NSMutableArray中,然后将NSMutableArray存储到NSDictionary中。 NSDictionary的键是foldername,NSDictionary的值是NSMutableArray。 现在我如何在NSUserDefaults中存储和检索NSDictionary 我的工作如下: NSMutableArray *imageArray=[[NSMutableArray alloc] init]; [imageArray addObject:sel

我将UIImage存储在NSMutableArray中,然后将NSMutableArray存储到NSDictionary中。 NSDictionary的键是foldername,NSDictionary的值是NSMutableArray。 现在我如何在NSUserDefaults中存储和检索NSDictionary

我的工作如下:

NSMutableArray *imageArray=[[NSMutableArray alloc] init];
[imageArray addObject:selectedImage];


[allFolderWithImageDict setValue:imageArray forKey:@"UniqueFolderName"];

NSUserDefaults *defauktCenter = [NSUserDefaults standardUserDefaults];
[defauktCenter setValue:allFolderWithImageDict forKey:@"FolderImageDict"];
[defauktCenter synchronize];
但NSDictionary并没有保存在NSUserDefaults中

请举例说明


感谢

存储和检索自定义对象的值,您可以使用
NSKeyedArchiver
nskeyedunachiver
类:

// To Save. . .
NSData *resData = [NSKeyedArchiver archivedDataWithRootObject:allFolderWithImageDict];
[[NSUserDefaults standardUserDefaults] setObject:resData forKey:@"FolderImageDict"];

// To Load. . .
NSData *respData = [[NSUserDefaults standardUserDefaults] objectForKey:@"FolderImageDict"];
resultDictionary = [NSKeyedUnarchiver unarchiveObjectWithData:respData];
NSLog(@"dict :: %@",resultDictionary);

祝你好运

要将
UIImage
对象存储在
NSUserDefaults
中,您需要为
UIImage
提供一个实现
NSCoding
协议的类别实现

这里有一个:


使用NSMutableDictionary而不是NSDictionary…)

以及检索字典中存储的数据

  NSUserDefaults *d = [NSUserDefaults standardUserDefaults];

  NSString *loadname1 = [d objectForKey:@"FolderImageDict"];

  NSLog(@"%@", loadname1);

我从这个链接得到了答案