2014-02-26 3 views
1
  • 이미지가 특정 디렉토리에서만 제공되는 사용자 정의 이미지 라이브러리가 필요한 프로젝트에서 작업 중입니다.
  • 그래서 문서 디렉토리에 하나의 디렉토리를 만들고 스크린 샷과 같이 "ImageFolder"번들 경로 디렉토리에서 파일 을 복사하고 있습니다.디렉토리 BundlePath의 콘텐츠 목록 가져 오기

  • 나는 다른 코드를 시도했지만 항상 배열 nil을 얻습니다. 나는 경로에 폴더가 없다는 것을 알고 있지만 어떻게하는지 말해주십시오.

- 내가>

  1. 이 문서 디렉토리에 디렉토리 "XYZ"를 만들기 원하는 것은.

  2. 모든 파일을 "ImageFolder"에서 "xyz"로 복사하십시오.

enter image description here

// ==================================== ============================

enter image description here

// =========== ========================================================================================================== ===

enter image description here

+0

dcoument 디렉토리에 imagefolder 디렉토리를 복사 할 수 있습니다. 이 링크를 사용할 수 있습니다 http://stackoverflow.com/questions/17669944/copy-folder-from-main-bundle-to-main-bundle-to-documents-directory-in-iphone –

답변

1

ImageFolder의 스크린 샷은 Xcode 프로젝트의 그룹이므로 해당 그룹과 관련된 모든 항목이 앱에 복사되지는 않습니다. 해당 응용 프로그램의 이미지가 복사본 번들 리소스 빌드 단계에 있으면 응용 프로그램 번들 (하위 폴더가 아님)에 직접 복사됩니다.

새 복사본 파일 빌드 단계를 추가하고 폴더 이름을 설정 한 다음 이미지를 해당 폴더로 이동해야합니다.

일단 이미지를 복사하려는 이유를 생각해보십시오. 사용자가 편집을 할 수 있습니까? 그렇지 않다면 이미지를 복사하는 것은 공간의 낭비입니다. 사용자가 이미지 중 일부를 '삭제'할 수 있다면 이미지 목록을 숨기거나 필터링하기 위해 '삭제 된 항목'plist 또는 사용자 기본값을 저장하는 것이 좋습니다.

+0

나중에 감사합니다. 나는 같은 방식으로 생각하고 있습니다. 해당 plist를 사용하여 이미지를 사용자 지정 라이브러리에 추가하십시오. –

1

이 코드는

-(void) copyDirectory:(NSString *)directory { 

    NSFileManager *fileManager = [NSFileManager defaultManager]; 
    NSError *error; 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *documentDBFolderPath = [documentsDirectory stringByAppendingPathComponent:directory]; 
    NSString *resourceDBFolderPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:directory]; 

    if (![fileManager fileExistsAtPath:documentDBFolderPath]) { 

     //Create Directory! 
     [fileManager createDirectoryAtPath:documentDBFolderPath withIntermediateDirectories:NO attributes:nil error:&error]; 

     NSArray *fileList = [fileManager contentsOfDirectoryAtPath:resourceDBFolderPath error:&error]; 
     for (NSString *s in fileList) { 
      NSString *newFilePath = [documentDBFolderPath stringByAppendingPathComponent:s]; 
      NSString *oldFilePath = [resourceDBFolderPath stringByAppendingPathComponent:s]; 
      if (![fileManager fileExistsAtPath:newFilePath]) { 
       //File does not exist, copy it 
       [fileManager copyItemAtPath:oldFilePath toPath:newFilePath error:&error]; 
      } else { 
       [fileManager removeItemAtPath:newFilePath error:&error]; 
       [fileManager copyItemAtPath:oldFilePath toPath:newFilePath error:&error]; 
      } 
     } 

     [self info:@"Copy finish!"]; 
    } 
} 

디렉토리에 복사 할 폴더의 이름을 추가 작동

편집 :

폴더 참조로 추가해야합니다.엑스 코드에서 프로젝트로 폴더를 드래그

enter image description here

+0

아니요 이미이 기능이 작동하지 않습니다. –

+0

참조로 폴더를 추가해야하며 내 대답이 업데이트됩니다. 귀하의 폴더가 노란 파랑이 아니야 노란색 –

+0

나중에 이것에 대해 잘 모른다. 감사합니다. –

0

는 당신이 현재 가지고하는 그룹 (노란색 폴더 아이콘) (물리적가 하위 폴더에없는)는 "추가 된 폴더에 대한 폴더를 참조 만들기"를 선택합니다 - 필요한 작업은 Xcode 외부에 폴더를 만들고 필요한 이미지를 프로젝트에 끌어다 놓는 것입니다. 파란색 폴더 아이콘이 있어야 명령이 작동합니다.

Xcode에 이미지를 소개 할 때마다 컴파일하고 번들에 넣을 때마다 이미지를 계속 유지할 필요가 없습니다.

+0

예, 이걸 잘 했어요. 감사합니다. –