123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- //
- // CPDFController.m
- // PDFViewer
- //
- // Created by kdan on 2022/11/14.
- //
- #import <ComPDFKit/ComPDFKit.h>
- #import "CPDFListController.h"
- #import "CPDFModel.h"
- #import "CPDFViewController.h"
- @interface CPDFListController () <UITableViewDataSource,UITableViewDelegate>
- @property (nonatomic,strong) UITableView *tableView;
- @property (nonatomic,strong) NSMutableArray *dataArray;
- @end
- @implementation CPDFListController
- - (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];
-
- for (NSInteger i = 0; i < fileArray.count; ++i) {
-
- if ([fileArray[i] isEqualToString:@".DS_Store"]) {
- continue;
- }
-
- NSString *subFilePath = [[self.path stringByAppendingString:@"/"] stringByAppendingString:fileArray[i]];
-
- CPDFModel *model = [[CPDFModel alloc] init];
- model.fileName = fileArray[i];
- model.filePath = subFilePath;
-
- [_dataArray addObject:model];
-
- }
- }
- 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.textLabel.text = [self.dataArray[indexPath.row] fileName];
- return cell;
- }
- #pragma mark - UITableViewDelegate
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
-
- BOOL isDir = NO;
-
- NSFileManager *defaultManager = [NSFileManager defaultManager];
- [defaultManager fileExistsAtPath:[self.dataArray[indexPath.row] filePath] isDirectory:&isDir];
-
- if (isDir) {
- CPDFModel *model = [[CPDFModel alloc] init];
- model.filePath = [[self.dataArray[indexPath.row] filePath] stringByAppendingString:@"/"];
- CPDFListController *pdfListController = [[CPDFListController alloc] initWithModel:model];
- [self.navigationController pushViewController:pdfListController animated:YES];
-
- } else {
-
- CPDFViewController *pdfViewcontroller = [[CPDFViewController alloc] initWithPath:[self.dataArray[indexPath.row] filePath]];
- // UIPageControl *pageControl = [[UIPageControl alloc] init];
- // pdfViewcontroller.navigationItem.rightBarButtonItem ;
- [self.navigationController pushViewController:pdfViewcontroller animated:YES];
-
- }
- }
- @end
|