遍历指定目录下的文件,将复合条件的文件加载到列表(UITableView))
本站最新网址:[url]http://www.helmsmansoft.com [/url] 欢迎关注
- (void)viewDidLoad{ NSFileManager *fileManager = [[NSFileManager defaultManager] init]; everyTitle = [[NSMutableArray alloc] init]; NSArray *filePaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *filePath = [filePaths objectAtIndex:0];// NSLog(@"%@",filePath); NSDirectoryEnumerator *direnum = [fileManager enumeratorAtPath:filePath]; // NSMutableArray *array = [[NSMutableArray alloc] init]; NSString *fileName; while ((fileName = [direnum nextObject])) { if([[fileName pathExtension] isEqualToString:@"pdf"]){ NSArray *strings = [fileName componentsSeparatedByString:@"."]; NSString *fileTitle = [strings objectAtIndex:[strings count]-2]; [everyTitle addObject:fileTitle]; } } uiController = [[UIViewController alloc] init]; [uiController setTitle:@"目录"]; navController = [[UINavigationController alloc] initWithRootViewController:uiController]; navController.view.frame = CGRectMake(0, 0, 320, 460); [self.view addSubview:navController.view]; self.uiController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(tableUpdata)];// self.uiController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"刷新列表" style:UIBarButtonItemStyleBordered target:self action:@selector(tableUpdata)]; tableView *tableViews = [[tableView alloc] initWithStyle:UITableViewStylePlain]; tableViews.view.frame = CGRectMake(0, 45, 320, 460); [tableViews theValue:everyTitle]; [self.view addSubview:tableViews.view];// [tableViews release]; }