uploadFileRecordBodyView.m 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. //
  2. // uploadFileRecordBodyView.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2023/11/15.
  6. //
  7. #import "uploadFileRecordBodyView.h"
  8. #import "uploadFileRecordCell.h"
  9. #import "UIScrollView+EmptyDataSet.h"
  10. #import "uploadFileDataModel.h"
  11. @interface uploadFileRecordBodyView ()<UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
  12. @property (nonatomic,strong) UIScrollView *bgScrollV;
  13. @end
  14. @implementation uploadFileRecordBodyView
  15. - (id)initWithFrame:(CGRect)frame{
  16. self = [super initWithFrame:frame];
  17. _selectIndex = 1;
  18. [self drawAnyView];
  19. return self;
  20. }
  21. - (void)drawAnyView{
  22. [self setBackgroundColor:[UIColor whiteColor]];
  23. NSInteger maxNum = 3;
  24. _bgScrollV = [[UIScrollView alloc] init];
  25. _bgScrollV.showsHorizontalScrollIndicator = NO;
  26. _bgScrollV.pagingEnabled = YES;
  27. _bgScrollV.delegate = self;
  28. [self addSubview:_bgScrollV];
  29. [_bgScrollV mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.left.mas_equalTo(0);
  31. make.right.mas_equalTo(0);
  32. make.top.mas_equalTo(0);
  33. make.bottom.mas_equalTo(0);
  34. }];
  35. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  36. mainBlock(^{
  37. CGRect frame = self->_bgScrollV.frame;
  38. self->_bgScrollV.contentSize = CGSizeMake(maxNum* SCREEN_W, frame.size.height);
  39. for (NSInteger i= 0; i<maxNum; i++) {
  40. UITableView *curTableview = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  41. curTableview.delegate = self;
  42. curTableview.dataSource = self;
  43. curTableview.showsVerticalScrollIndicator = NO;
  44. curTableview.showsHorizontalScrollIndicator = NO;
  45. // _tableView.contentInset = UIEdgeInsetsMake(-H_STATE_BAR, 0, 0, 0);
  46. [curTableview setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  47. [curTableview setSeparatorColor:[UIColor clearColor]];
  48. [curTableview setBackgroundColor:[UIColor clearColor]];
  49. [curTableview setTableFooterView:[UIView new]];
  50. [curTableview setBounces:YES];
  51. if (@available(iOS 15.0, *)) {
  52. curTableview.sectionHeaderTopPadding = 0;
  53. }
  54. [self->_bgScrollV addSubview:curTableview];
  55. curTableview.tag = 10 +i;
  56. //空数据引入第三方开源处理
  57. curTableview.emptyDataSetSource = self;
  58. curTableview.emptyDataSetDelegate = self;
  59. [curTableview mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.left.mas_equalTo(SCREEN_W * i);
  61. make.width.mas_equalTo(SCREEN_W);
  62. make.top.mas_equalTo(0);
  63. make.height.mas_equalTo(frame.size.height);
  64. }];
  65. }
  66. });
  67. });
  68. }
  69. #pragma mark - 列表委托
  70. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  71. return 1;
  72. }
  73. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  74. NSInteger tag = tableView.tag - 10;
  75. if(_allDataArr && tag <_allDataArr.count){
  76. NSMutableArray *curArr = _allDataArr[tag];
  77. return curArr.count;
  78. }
  79. return 0;
  80. }
  81. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  82. NSInteger row = indexPath.row;
  83. static NSString *identifier = @"uploadFileRecordCell";
  84. uploadFileRecordCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  85. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  86. if (!cell){
  87. cell = [[uploadFileRecordCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  88. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  89. [cell setBackgroundColor:[UIColor clearColor]];
  90. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  91. }
  92. NSInteger tag = tableView.tag - 10;
  93. if(_allDataArr && tag <_allDataArr.count){
  94. NSMutableArray *curArr = _allDataArr[tag];
  95. if(row < curArr.count){
  96. uploadFileDataModel *model = curArr[row];
  97. cell.curUploadFileDataModel = model;
  98. }
  99. }
  100. return cell;
  101. }
  102. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  103. return 70;
  104. }
  105. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  106. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  107. }
  108. //- (void)scrollViewDidScroll:(UIScrollView *)scrollView
  109. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
  110. {
  111. if(_bgScrollV != scrollView) return;
  112. CGFloat x = scrollView.contentOffset.x;
  113. NSInteger index = (x+1)/SCREEN_W;
  114. index += 1;//因为头部是从1开始的
  115. //HLog(@"index:%ld",index);
  116. if(_didScrollFun){
  117. _didScrollFun(index);
  118. }
  119. }
  120. #pragma mark 空数据
  121. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  122. return [UIImage imageNamed:@"uploadFile_noData"];
  123. }
  124. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  125. NSString *text = NSLocalizedString(@"File_upload_Record_no_data",nil);
  126. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  127. NSForegroundColorAttributeName: HW999999Color};
  128. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  129. }
  130. //调整图片位置
  131. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  132. return -150;
  133. }
  134. - (void)setSelectIndex:(NSInteger)selectIndex
  135. {
  136. _selectIndex = selectIndex;
  137. CGPoint poit = _bgScrollV.contentOffset;
  138. poit.x = SCREEN_W * (selectIndex -1);
  139. [UIView animateWithDuration:0.2 animations:^{
  140. self->_bgScrollV.contentOffset = poit;
  141. }];
  142. }
  143. - (void)setAllDataArr:(NSMutableArray *)allDataArr
  144. {
  145. _allDataArr = allDataArr;
  146. //刷新数据
  147. [self reloadAllDataFun];
  148. }
  149. #pragma mark 熟悉全部数据
  150. - (void)reloadAllDataFun
  151. {
  152. mainBlock(^{
  153. NSArray *subViews = [self->_bgScrollV subviews];
  154. for (UITableView *tableView in subViews) {
  155. if([tableView isKindOfClass:[UITableView class]]){
  156. [tableView reloadData];
  157. }
  158. }
  159. });
  160. }
  161. @end