Path: blob/main/Natives/FileListViewController.m
589 views
#import "FileListViewController.h"12@interface FileListViewController () {3}45@property(nonatomic) NSMutableArray *fileList;67@end89@implementation FileListViewController1011- (void)viewDidLoad {12[super viewDidLoad];1314if (self.fileList == nil) {15self.fileList = [NSMutableArray array];16} else {17[self.fileList removeAllObjects];18}1920// List files21NSFileManager *fm = [NSFileManager defaultManager];22NSArray *files = [fm contentsOfDirectoryAtPath:self.listPath error:nil];23for(NSString *file in files) {24NSString *path = [self.listPath stringByAppendingPathComponent:file];25BOOL isDir = NO;26[fm fileExistsAtPath:path isDirectory:(&isDir)];27if(!isDir && [file hasSuffix:@".json"]) {28[self.fileList addObject:[file stringByDeletingPathExtension]];29}30}3132[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];33}3435- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section36{37return self.fileList.count;38}3940- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath41{42UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];4344if (cell == nil) {45cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];46}4748cell.textLabel.text = [self.fileList objectAtIndex:indexPath.row];49return cell;50}5152- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {53[self dismissViewControllerAnimated:YES completion:nil];5455self.whenItemSelected(self.fileList [indexPath.row]);56}5758- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {59if (editingStyle == UITableViewCellEditingStyleDelete) {60NSString *str = [self.fileList objectAtIndex:indexPath.row];61NSFileManager *fm = [NSFileManager defaultManager];62NSString *path = [NSString stringWithFormat:@"%@/%@.json", self.listPath, str];63if (self.whenDelete != nil) {64self.whenDelete(path);65}66[fm removeItemAtPath:path error:nil];67[self.fileList removeObjectAtIndex:indexPath.row];68[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];69}70}7172@end737475