iPhone:将 NSMutableArray 转换为 NSData 并存储 &已检索问题

发布于 2024-12-07 09:38:17 字数 773 浏览 0 评论 0原文

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

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

我在 appdelegate 中初始化 nsmutablearray (appDelegate.categories) 和 nsmutabledictionary。

提前致谢。

I am facing a problem, that is to convert NSMutableArray into NSData and stored & retrieved that array into rootviewcontroller so please give me idea. Here is the code I'm working with:

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

I am initialize nsmutablearray (appDelegate.categories) and nsmutabledictionary in appdelegate.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

誰認得朕 2024-12-14 09:38:17

据我了解,您想要保存图像并检索它们。您可以使用以下两种方法之一将图像转换为 NSDataUIImagePNGRepresentationUIImageJPEGRepresentation,具体取决于图像的类型。然后您可以保存这些数据 -

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.

From what I understand, you want to save your images and retrieve them. You can convert your image to NSData using one of the 2 methods, UIImagePNGRepresentation or UIImageJPEGRepresentation depending on the type of the image. You can then save this data-

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文