我遇到了一个问题,即将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。
提前致谢。
答案 0 :(得分:0)
根据我的理解,您希望保存图像并检索它们。您可以使用以下两种方法之一NSData
或UIImagePNGRepresentation
将图片转换为UIImageJPEGRepresentation
,具体取决于图片的类型。然后,您可以保存此数据 -
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.