ios - 我们如何在 NSMutableArray 中添加带有 Image 的 NSMutableDictionary 作为对象,并将该数组写入 Plist 中

标签 ios uiimage nsmutablearray plist nsmutabledictionary

我想将 UIImage 存储在 NSMutableDictionary 中。

NSData *imgData = UIImagePNGRepresentation(picture.image);
[studDict setValue:imgData forKey:@"Photo"];

哪里, studDict 是 NSMutableDictionary。 图片是UIImageView。

并将此字典添加为对象存储在 NSMutableArray 中。

    [studArrayPlist addObject:detailDict];

哪里, studArrayPlist 是 NSMutableArray。 detailDict 是带有 UIImage 的 NSMutableDictionary。

并将这个 NSMutableArray 写入 plist 中。

[studArrayPlist writeToFile:plistPath atomically: TRUE];

哪里, studArrayPlist 是 NSMutableArray 存储 NSMutableDictionary 和 UIImage。

如果不写在 plist 中,这将不起作用。 并且不要给出任何错误。 我还想从 plist 中检索数组中的所有数据。

最佳答案

检查对象是否添加到字典和数组中。如果没有则分配 NSMutableArray 和 NSMutableDictionary。

NSMutableDictionary *studDict=[[NSMutableDictionary alloc] init];

[studDict setValue:imgData forKey:@"Photo"];

NSMutableArray * studArrayPlist =[[NSMutableArray alloc] init];
[studArrayPlist addObject:studDict];
[studArrayPlist writeToFile: plistPath atomically:YES];

关于ios - 我们如何在 NSMutableArray 中添加带有 Image 的 NSMutableDictionary 作为对象,并将该数组写入 Plist 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22836815/

相关文章:

c# - 更新后缺少iOS模拟器列表

objective-c - 图像上的 UILabel

iphone - 如何在运行时在 iPhone sdk 中删除图像背景

IOS 根据 NSMutableArray 值更改 Uitableview 中的 Accessory View Cell Image

ios - 如何控制页面显示为在 iOS 的 UIWebView 中加载的 PDF(转到页面)

ios - 将 JSON 响应与字符串进行比较

UITextfield 的 iOS 安全文本输入

IOS:在 UIImage 中设置 alpha

iOS NSMutablearray 释放行为

iphone - 如何将多个 NSIndexPath 添加到 NSMutableArray