MyPaperViewController.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //
  2. // MyPaperViewController.m
  3. // ChinaTheoryNetwork
  4. //
  5. // Created by 张毅成 on 2019/4/3.
  6. // Copyright © 2019 张毅成. All rights reserved.
  7. //
  8. #import "MyPaperViewController.h"
  9. #import "MyPaperTableViewCell.h"
  10. @interface MyPaperViewController ()<UIScrollViewDelegate, UITableViewDelegate, UITableViewDataSource>
  11. @property (weak, nonatomic) IBOutlet UIView *viewLine;
  12. @property (weak, nonatomic) IBOutlet UIView *viewBackground;
  13. @property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *arrayButtonTop;
  14. @property (weak, nonatomic) IBOutlet UIView *viewTop;
  15. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *viewTopToTop;
  16. @property (strong, nonatomic) UIScrollView *scrollViewBackground;
  17. /**
  18. tableview数组
  19. */
  20. @property (strong, nonatomic) NSMutableArray *arrayTableView;
  21. /**
  22. 正常显示的数据的数组
  23. */
  24. @property (strong, nonatomic) NSMutableArray *arrayData;
  25. /**
  26. 分页数组
  27. */
  28. @property (strong, nonatomic) NSMutableArray *arrayPageNo;
  29. @end
  30. @implementation MyPaperViewController
  31. - (NSMutableArray *)arrayData {
  32. if (!_arrayData) {
  33. _arrayData = @[
  34. @[@"",@"",@"",@""],
  35. @[@"",@"",@""],
  36. @[@"",@""]
  37. ].mutableCopy;
  38. }
  39. return _arrayData;
  40. }
  41. - (NSMutableArray *)arrayTableView {
  42. if (!_arrayTableView) {
  43. _arrayTableView = @[].mutableCopy;
  44. }
  45. return _arrayTableView;
  46. }
  47. - (NSMutableArray *)arrayPageNo {
  48. if (!_arrayPageNo) {
  49. _arrayPageNo = @[].mutableCopy;
  50. }
  51. return _arrayPageNo;
  52. }
  53. - (UIScrollView *)scrollViewBackground {
  54. if (!_scrollViewBackground) {
  55. _scrollViewBackground = [[UIScrollView alloc] initWithFrame:(CGRect){0, 0, kGXScreenWidth, self.viewBackground.height}];
  56. _scrollViewBackground.delegate = self;
  57. _scrollViewBackground.pagingEnabled = true;
  58. _scrollViewBackground.userInteractionEnabled = true;
  59. }
  60. return _scrollViewBackground;
  61. }
  62. - (void)viewDidLoad {
  63. [super viewDidLoad];
  64. self.title = @"我的论文";
  65. [self.viewBackground addSubview:self.scrollViewBackground];
  66. [self makeTableView];
  67. }
  68. - (void)makeTableView {
  69. [self.arrayButtonTop enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  70. UIButton *button = obj;
  71. button.tag = idx;
  72. UITableView *tableView = [[UITableView alloc] initWithFrame:(CGRect){ idx * kGXScreenWidth,0,kGXScreenWidth, self.viewBackground.height} style:(UITableViewStylePlain)];
  73. tableView.delegate = self;
  74. tableView.dataSource = self;
  75. tableView.backgroundColor = [UIColor whiteColor];
  76. tableView.tag = idx;
  77. tableView.tableFooterView = [UIView new];
  78. WeakSelf(self)
  79. tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  80. StrongSelf(weakself)
  81. [strongself.arrayData replaceObjectAtIndex:tableView.tag withObject:@[].mutableCopy];
  82. [strongself.arrayPageNo replaceObjectAtIndex:tableView.tag withObject:@(1)];
  83. }];
  84. tableView.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{
  85. StrongSelf(weakself)
  86. NSInteger number = [strongself.arrayPageNo[tableView.tag] integerValue];
  87. number++;
  88. [strongself.arrayPageNo replaceObjectAtIndex:tableView.tag withObject:@(number)];
  89. }];
  90. [self.scrollViewBackground addSubview:tableView];
  91. [self.arrayTableView addObject:tableView];
  92. [self.arrayPageNo addObject:@(1)];
  93. [self.arrayData addObject:@[].mutableCopy];
  94. }];
  95. self.scrollViewBackground.contentSize = CGSizeMake(kGXScreenWidth * self.arrayTableView.count, 0);
  96. }
  97. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  98. if (scrollView == self.scrollViewBackground) {
  99. UIButton *button;
  100. [self.arrayButtonTop enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  101. UIButton *button = obj;
  102. button.userInteractionEnabled = false;
  103. }];
  104. NSString *str = [NSString stringWithFormat:@"%0.0f",self.scrollViewBackground.contentOffset.x/kGXScreenWidth];
  105. if (self.scrollViewBackground.contentOffset.x == kGXScreenWidth * str.integerValue) {
  106. button = self.arrayButtonTop[str.integerValue];
  107. [self didTouchButtonTop:button];
  108. }
  109. }
  110. }
  111. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  112. return 1;
  113. }
  114. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  115. NSArray *arrayTmp = self.arrayData[section];
  116. return arrayTmp.count;
  117. }
  118. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  119. MyPaperTableViewCell *cell0 = [MyPaperTableViewCell cellWithTableView:tableView AndIndex:0];
  120. MyPaperTableViewCell *cell1 = [MyPaperTableViewCell cellWithTableView:tableView AndIndex:1];
  121. if (tableView.tag == 1) {
  122. [cell1.buttonBuy addEventHandler:^(id sender) {
  123. SHOWSUCCESS(@"")
  124. } forControlEvents:(UIControlEventTouchUpInside)];
  125. return cell1;
  126. }
  127. return cell0;
  128. }
  129. - (IBAction)didTouchButtonTop:(UIButton *)sender {
  130. [self.arrayButtonTop enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  131. UIButton *button = obj;
  132. button.selected = false;
  133. button.userInteractionEnabled = true;
  134. }];
  135. sender.selected = true;
  136. [UIView animateWithDuration:0.2 animations:^{
  137. self.viewLine.centerX = sender.centerX;
  138. self.scrollViewBackground.contentOffset = CGPointMake(kGXScreenWidth * sender.tag, 0);
  139. }];
  140. }
  141. @end