如何更改文档目录文件夹索引号?

时间:2017-03-11 17:30:30

标签: ios objective-c nsdocumentdirectory

我使用 PGDataSource 类在文档目录中创建了文件夹。

self.itmesDir = [self getDocumentPathForFileName: @"items"];

 -(NSString *) getDocumentPathForFileName: (NSString *) filename {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent: filename];
}

-(NSString *) createFolderWithName: (NSString *) name {
NSString *folderPath = [self.itmesDir stringByAppendingPathComponent: name];
[self.fileManager createDirectoryAtPath: folderPath withIntermediateDirectories: FALSE attributes:nil error: nil];
return folderPath;
}

这是我的集合视图数据源方法。

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

AlbumCollectionViewCell *cell = [_albumCollectionView dequeueReusableCellWithReuseIdentifier:@"albumCell" forIndexPath:indexPath];
//Label
NSString *folderName = [self.dataSource folderNameForIndex: (int)indexPath.row];
cell.albumTitleLabel.text = folderName;
//Sublabel
NSDictionary *_dicItem = [self.dataSource numberOfFilesForFolder:folderName];
int files = [self.dataSource numberOfFilesForDictionary:_dicItem];
NSString *folderDetails = [self.dataSource getPhotosStringFromNumber: _dicItem];
cell.albumDetailsLabel.text = folderDetails;  
return cell;
}

这里是获取文件夹名称

的方法
-(NSString *) folderNameForIndex: (int) index {
NSArray *folderList = [self.fileManager contentsOfDirectoryAtPath: self.itmesDir error: nil];
return [folderList objectAtIndex: index];
}

我在集合视图中显示文件夹。现在我可以更改文件夹名称,但是当我在集合视图中移动文件夹时,我需要更改文件夹的位置或索引号。我怎样才能做到这一点?

0 个答案:

没有答案