내 문제 :이 주제에 관한이 포럼 (Getting a list of files in a directory with a glob), 에 대해이 포럼을 이미 검색했지만 아직 해결해야 할 과제가 있습니다.어레이의 skipHiddenFiles에 여전히 수정이 필요합니다.
Objective-C를 사용하여 내 iOS 루트 "문서 디렉토리"에 저장된 파일 배열로 tableview를 채우고 있습니다.
파일은 .caf 오디오 파일 (예 : audio_1.caf, audio_2.caf 등)입니다. NSArray _audioFileArray를 사용하여 UITableview 셀의 파일을 나열합니다.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = @"simpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:simpleTableIdentifier];
}
//add the text display that is drawn from the array list
cell.textLabel.text = [_audioFileArray objectAtIndex:indexPath.row];
//cell.textLabel.text = [NSString stringWithFormat:@"%@.!!", _audioFileArray];
return cell;
}
이 배열 밖으로 콘솔 프린트이다
2016년 9월 25일 18 : 27 : 08.278 NewAudioPlayerTest [3349 : 60B] AudioFileArray 확인 :
-
( 을 ".DS_Store",
"audio 1.caf",
"audio 10.caf",
" 오디오 2.caf ",
"오디오 3.caf ",
"오디오 4.caf ",
"오디오 5.caf ",
"오디오 6.caf ",
"오디오 7.caf " ,
"오디오 8.caf",
"오디오 9.caf" )
참고 또한 인구의 tableview의 NSLog에 된 .DS_Store 보이지 않는 파일, I 돈되는 게재 필요 없어요. 오디오 파일이 필요합니다. 미래의 플레이.
필자는 성공한 조건 자 필터를 사용하고 "NSDirectoryEnumerationSkipsHiddenFiles"메소드를 일부 결과와 함께 사용해 보았습니다. 하면 아래 그림과 같이, 내가 콘솔에서 전체 URL과 함께 파일 확장자의 난도질 버전을 배열로이 방법의 결과에 대한 I NSLog ...
**"file:///Users/aName/Library/Developer/CoreSimulator/Devices/D144B87B-F1A6-460E-9628-5C203396B60D/data/Applications/C85E57DD-E183-48C5-8D64-F9C497E9AA2E/Documents/audio%201.caf",
"file:///Users/aName/Library/Developer/CoreSimulator/Devices/D144B87B-F1A6-460E-9628-5C203396B60D/data/Applications/C85E57DD-E183-48C5-8D64-F9C497E9AA2E/Documents/audio%202.caf",**
.. 그리고 곧.
내 DetailViewController.m 파일이 모두 처리되는 코드의 대부분은 다음과 같습니다
@interface FileViewController()
@end
@implementation FileViewController
int count;
@synthesize fileArray = _fileArray;
@synthesize fileName = _fileName;
@synthesize audioFileArray = _audioFileArray;
@synthesize contents = _contents;
@synthesize fileURL = _fileURL;
- (void)viewDidLoad {
[super viewDidLoad];
NSFileManager *fileManager = [NSFileManager defaultManager];
_audioFileArray = [[NSMutableArray alloc] init];
_fileName = [NSString stringWithFormat:@"audio %d", count];
NSArray *paths = [NSArray arrayWithObjects: [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject],
_fileName,
nil];
NSString *documentsDirectory = [paths objectAtIndex:0];
// WORKS with this, but whole mangled URL ——>
_fileURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@",[paths objectAtIndex:0]]];
NSError *error = nil;
///—> not working!!
_audioFileArray = [fileManager contentsOfDirectoryAtPath:documentsDirectory error:&error];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"pathExtension='.caf'"];
[_audioFileArray filteredArrayUsingPredicate:predicate];
_contents = [fileManager contentsOfDirectoryAtURL:_fileURL includingPropertiesForKeys: [NSArray arrayWithObject:NSURLNameKey] options:NSDirectoryEnumerationSkipsHiddenFiles error:nil];
NSArray *theFiles = [fileManager contentsOfDirectoryAtURL:[NSURL fileURLWithPath:[paths objectAtIndex:0]]
includingPropertiesForKeys:[NSArray arrayWithObject:NSURLNameKey]
options:NSDirectoryEnumerationSkipsHiddenFiles
error:nil];
NSLog(@“skipHiddenFiles log ---> %@“,_contents);
NSLog(@"now predicate ---> %@",predicate);
이 코드가 엉망의 비트를 볼 수에 대한, (네, 죄송합니다) 내가 원했던 것은 숨겨진 파일을 필터링하여 NSArray _audioFileArray 인스턴스 메소드를 사용하는 것이다. 여기에 접근하여 필터링 작업을 수행하는 가장 좋은 방법은 어떤 솔루션이나 제안입니까? 여기에서 잘못된 점이 있습니다.
감사합니다. (아래 그림에 게시 내 배열의있는 tableView 목록)
칼. 귀하의 회신과 제안을 보내 주셔서 감사 드리며, 지금까지 회신을 업데이트하지 않으신 것에 대해 유감스럽게 생각합니다. 바쁜 작업 일정 및 기타 물건 등 – richg
나는 술어 클래스 메서드를 사용하여 끝났다 : _audioFileArray = [fileManager contentsOfDirectoryAtPath : documentsDirectory 오류 : & 오류]; // NSPredicate * predicate = [NSPredicate predicateWithFormat : <# (NSString *) #> argumentArray : <# (NSArray *) #>; NSPredicate * predicate = [NSPredicate predicateWithFormat : @ "SELF ENDSWITH [cd] % @", @ ".caf"]; _filteredArray = [_audioFileArray filteredArrayUsingPredicate : predicate]; – richg
이 배열은 필터링 된 .caf 파일 만 사용하여 배열을 반환합니다. 유일한 것은 iOS 문서 폴더에있는 파일을 편집 할 수 있어야한다는 것입니다. 그래서 나는 NSMutableArray의 필터 배열을 필요로 할 것입니다. 어쨌든, 너는 내가 이것을 멀리하도록 도왔다. 매우 감사. – richg