사진을 정렬 할 수 있도록 폴더에 폴더를 생성하고 싶지만 내 디렉토리에 모든 사진을 표시하고 싶습니다. 모든 사진을 여러 폴더에 표시하고 싶습니다. 코드를 사용하고 있습니다.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가 나타나지만 나는 그렇지 않습니다. 여러 폴더에있는 모든 그림을 보여주는 내 방식이 잘못 되었습니까? 나는 어떤 오류도 없다.
이 라인의 목적은 무엇인가 :있는 NSString * 위치 = @ "바지"그런 다음 폴더와 내용을 통해 루프를 실행할 수있는 그런
: 뭔가 더처럼 당신은 아마 원하는 @ "위쪽"@ "오른쪽"@ "왼쪽"@ "아래쪽"@ "위로"; ? – rdelmar
저장 한 사진을 검색합니다. 디렉토리 파일에 폴더를 만들었습니다. 그것들은 디렉토리 파일의 폴더입니다. UICollectionView가 그 파일에있는 모든 그림을 보여주기를 원합니다. – apple1384792
[allImagesArray objectAtIndex : indexPath.row] 행을 nslog했을 때 결과는 무엇입니까? – edzio27