2013-08-24 3 views
0

사진을 정렬 할 수 있도록 폴더에 폴더를 생성하고 싶지만 내 디렉토리에 모든 사진을 표시하고 싶습니다. 모든 사진을 여러 폴더에 표시하고 싶습니다. 코드를 사용하고 있습니다.CollectionView에 디렉토리의 사진이 없습니다.

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
    allImagesArray = [[NSMutableArray alloc] init]; 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *[email protected]"Bottoms"@"Top"@"Right"@"Left"@"Down"@"Up"; 
    NSString *fPath = [documentsDirectory stringByAppendingPathComponent:location]; 
    NSArray *directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath: fPath]; 
    collectionTrash.delegate =self; 
    collectionTrash.dataSource=self; 
    for(NSString *str in directoryContent){ 
     NSLog(@"i"); 
     NSString *finalFilePath = [fPath stringByAppendingPathComponent:str]; 
     NSData *data = [NSData dataWithContentsOfFile:finalFilePath]; 
     if(data) 
     { 
      UIImage *image = [UIImage imageWithData:data]; 
      [allImagesArray addObject:image]; 
      NSLog(@"array:%@",[allImagesArray description]); 
     }}} 

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView 
{ 
    NSLog(@"j"); 
    return 1; 
} 

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 
{ 
    return [allImagesArray count]; 


} 

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *reuseID = @"ReuseID"; 
    TrashCell *mycell = (TrashCell *) [collectionView dequeueReusableCellWithReuseIdentifier:reuseID forIndexPath:indexPath]; 
    UIImageView *imageInCell = (UIImageView*)[mycell viewWithTag:1]; 
    imageInCell.image = [allImagesArray objectAtIndex:indexPath.row]; 
    NSLog(@"a"); 
    return mycell; 
} 

내 코드를 보면 NSLOG i와 j를 알 수 있습니다. j가 나타나지만 나는 그렇지 않습니다. 여러 폴더에있는 모든 그림을 보여주는 내 방식이 잘못 되었습니까? 나는 어떤 오류도 없다.

+0

이 라인의 목적은 무엇인가 :있는 NSString * 위치 = @ "바지"그런 다음 폴더와 내용을 통해 루프를 실행할 수있는 그런

NSArray *locations = @[ @"Bottoms", @"Top", @"Right", @"Left", @"Down", @"Up" ]; 

: 뭔가 더처럼 당신은 아마 원하는 @ "위쪽"@ "오른쪽"@ "왼쪽"@ "아래쪽"@ "위로"; ? – rdelmar

+0

저장 한 사진을 검색합니다. 디렉토리 파일에 폴더를 만들었습니다. 그것들은 디렉토리 파일의 폴더입니다. UICollectionView가 그 파일에있는 모든 그림을 보여주기를 원합니다. – apple1384792

+0

[allImagesArray objectAtIndex : indexPath.row] 행을 nslog했을 때 결과는 무엇입니까? – edzio27

답변

0

여러 폴더가있는 경우 폴더를 반복하고 폴더 내용을 모두 처리해야합니다. 이 라인 동안

:

NSString *[email protected]"Bottoms"@"Top"@"Right"@"Left"@"Down"@"Up"; 

기술적으로 법적인가, 나는 당신이 당신을 위해 몇 가지 배열/반복 일을 할 것입니다 생각하는 것 같아요. 그렇지 않습니다. 그냥 모든 문자열을 연결합니다.

for(NSString *folder in locations) { 

    // get the folder contents 

    for(NSString *file in directoryContent) { 

     // load the image 

    } 
} 
+0

NSString 형식의 매개 변수에 NSArray Storng를 보내는 비 호환 포인터 유형을 말하면 오류가 발생합니다. 실행하면 충돌합니다. – apple1384792

+0

문자열을 사용할 때 배열을 전송하지 마십시오. 한 발 뒤로 물러서서 자신이하는 일에 대해 생각해보십시오. 이터 레이션에는 배열을 사용하고 경로에는 배열 내용을 사용하십시오. – Wain

관련 문제