我想将 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/