0

を使用して複数のディレクトリを作成しました

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

ディレクトリ名を宣言する場所がわかりません

4

1 に答える 1