// // CPDFController.m // PDFViewer // // Created by kdan on 2022/11/14. // #import "CPDFController.h" #import "CPDFModel.h" @interface CPDFController () @property (nonatomic,strong) UITableView *tableView; @property (nonatomic,strong) NSMutableArray *dataArray; @property (nonatomic,strong) NSMutableArray *pathArray; @end @implementation CPDFController - (instancetype)initWithModel:(CPDFModel *)model { if (self = [super init]) { [self setPath:model.filePath]; } return self; } - (NSArray *)dataArray { if (!_dataArray) { _dataArray = [NSMutableArray array]; NSFileManager *defaultManager = [NSFileManager defaultManager]; NSArray *fileArray = [defaultManager contentsOfDirectoryAtPath:self.path error:nil]; NSMutableArray *mArray = [NSMutableArray array]; for (NSInteger i = 0; i < fileArray.count; ++i) { CPDFModel *model = [[CPDFModel alloc] init]; model.fileName = fileArray[i]; [_dataArray addObject:model]; } [self setPathArray:mArray]; } return _dataArray; } - (void)viewDidLoad { [super viewDidLoad]; // Uncomment the following line to preserve selection between presentations. // self.clearsSelectionOnViewWillAppear = NO; // Uncomment the following line to display an Edit button in the navigation bar for this view controller. // self.navigationItem.rightBarButtonItem = self.editButtonItem; [self setTableView:[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]]; [self.tableView setDataSource:self]; [self.tableView setDelegate:self]; self.tableView.rowHeight = 50; self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; self.tableView.tableFooterView = [[UIView alloc] init]; [self.view addSubview:self.tableView]; } #pragma mark - UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *MyIdentifier = @"Path"; UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:MyIdentifier]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MyIdentifier]; } // cell.model = self.dataArray[indexPath.row]; cell.textLabel.text = [self.dataArray[indexPath.row] fileName]; return cell; } #pragma mark - UITableViewDelegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // CPDFViewCell *model = [[CPDFViewCell alloc] init]; // model.filePath = self.pathArray[indexPath.row]; // // *table = [[TableViewController alloc] initWithModel:model]; // [self.navigationController pushViewController:table animated:NO]; } @end