【发布时间】:2013-08-11 17:02:48
【问题描述】:
我使用
创建了多个目录NSArray *directoryNames = [NSArray arrayWithObjects:@"t",@"b",@"p",@"c", @"S", @"h", @"o",nil];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
for (int i = 0; i < [directoryNames count] ; i++) {
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:[directoryNames objectAtIndex:i]];
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:nil];
但是,我想对 UIImage 上显示的照片进行排序,并对用户使用 pickerview 选择的照片进行排序。我想知道要保存到我制作的这些特定目录中的代码。任何帮助是极大的赞赏!
更新我知道
在应用中的任何位置使用您创建的目录。
NSArray *directoryNames = [NSArray arrayWithObjects:@"tops",@"bottoms",@"right",@"left",nil];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
// This will return the folder name in the 0 position. In yours "tops"
NSString *topDirPath = [documentsDirectory stringByAppendingPathComponent:[directoryNames objectAtIndex:0]];
// This will return the file path in your "tops" folder
NSString *filePath = [topDirPath stringByAppendingPathComponent:@"MYIMAGE"];
存储图像文件
NSData *imageDataToStore = UIImagePNGRepresentation(image);
[imageDataToStore writeToFile:filePath atomically:YES];
我不知道在哪里声明我的目录名
【问题讨论】:
-
我在一个旧项目中找到了这一行 [self.library writeImageToSavedPhotosAlbum:img.CGImage metadata:nil completionBlock:nil];但我不是 100% 确定它有效:P
-
@Arbitur 那就是相册.....
-
哎呀对不起,我把它和别的东西混在一起了:S
标签: ios uiimage directory save