CPDFController.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // CPDFController.m
  3. // PDFViewer
  4. //
  5. // Created by kdan on 2022/11/14.
  6. //
  7. #import "CPDFController.h"
  8. #import "CPDFModel.h"
  9. @interface CPDFController () <UITableViewDataSource,UITableViewDelegate>
  10. @property (nonatomic,strong) UITableView *tableView;
  11. @property (nonatomic,strong) NSMutableArray *dataArray;
  12. @property (nonatomic,strong) NSMutableArray *pathArray;
  13. @end
  14. @implementation CPDFController
  15. - (instancetype)initWithModel:(CPDFModel *)model {
  16. if (self = [super init]) {
  17. [self setPath:model.filePath];
  18. }
  19. return self;
  20. }
  21. - (NSArray *)dataArray {
  22. if (!_dataArray) {
  23. _dataArray = [NSMutableArray array];
  24. NSFileManager *defaultManager = [NSFileManager defaultManager];
  25. NSArray *fileArray = [defaultManager contentsOfDirectoryAtPath:self.path error:nil];
  26. NSMutableArray *mArray = [NSMutableArray array];
  27. for (NSInteger i = 0; i < fileArray.count; ++i) {
  28. CPDFModel *model = [[CPDFModel alloc] init];
  29. model.fileName = fileArray[i];
  30. [_dataArray addObject:model];
  31. }
  32. [self setPathArray:mArray];
  33. }
  34. return _dataArray;
  35. }
  36. - (void)viewDidLoad {
  37. [super viewDidLoad];
  38. // Uncomment the following line to preserve selection between presentations.
  39. // self.clearsSelectionOnViewWillAppear = NO;
  40. // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
  41. // self.navigationItem.rightBarButtonItem = self.editButtonItem;
  42. [self setTableView:[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]];
  43. [self.tableView setDataSource:self];
  44. [self.tableView setDelegate:self];
  45. self.tableView.rowHeight = 50;
  46. self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  47. self.tableView.tableFooterView = [[UIView alloc] init];
  48. [self.view addSubview:self.tableView];
  49. }
  50. #pragma mark - UITableViewDataSource
  51. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  52. return self.dataArray.count;
  53. }
  54. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  55. static NSString *MyIdentifier = @"Path";
  56. UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:MyIdentifier];
  57. if (!cell) {
  58. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MyIdentifier];
  59. }
  60. // cell.model = self.dataArray[indexPath.row];
  61. cell.textLabel.text = [self.dataArray[indexPath.row] fileName];
  62. return cell;
  63. }
  64. #pragma mark - UITableViewDelegate
  65. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  66. // CPDFViewCell *model = [[CPDFViewCell alloc] init];
  67. // model.filePath = self.pathArray[indexPath.row];
  68. //
  69. // *table = [[TableViewController alloc] initWithModel:model];
  70. // [self.navigationController pushViewController:table animated:NO];
  71. }
  72. @end