MyTableView.m 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //
  2. // MyTableView.m
  3. // 老淘宝详情
  4. //
  5. // Created by Kobe24 on 2018/3/8.
  6. // Copyright © 2018年 SYD. All rights reserved.
  7. //
  8. #import "MyTableView.h"
  9. #import "HorizonScroll.h"
  10. #import "ChannelModel.h"
  11. #import "FwzBaseView.h"
  12. @interface MyTableView ()<UIScrollViewDelegate>
  13. @property (nonatomic, strong) UIScrollView *tabContentView;
  14. @property (nonatomic, strong) HorizonScroll *channelScroll;
  15. @property (nonatomic, strong) NSMutableArray *subSource;
  16. @end
  17. @implementation MyTableView
  18. - (void)scrollTop{
  19. for (UIView * view in self.tabContentView.subviews) {
  20. for (UIView * subview in view.subviews) {
  21. if ([subview isKindOfClass:[UITableView class]]) {
  22. UITableView * tabview = (UITableView *)subview;
  23. [tabview scrollToTop];
  24. }
  25. }
  26. }
  27. [self.tabContentView scrollToTop];
  28. }
  29. - (void)loadDataWithIndex:(NSInteger)index {
  30. FwzBaseView *baseView = (FwzBaseView *)[self.tabContentView viewWithTag:index];
  31. [baseView reloadData];
  32. }
  33. - (NSMutableArray *)subSource {
  34. if (_subSource == nil) {
  35. _subSource = [[NSMutableArray alloc] init];
  36. }
  37. return _subSource;
  38. }
  39. - (void)loadData:(HomeArticleModel *)model withWaitWorkArray:(TDWaitWorkModel *)waitModel{
  40. NSLog(@"MyTableView - loadData首页数据%@",model);
  41. [_subSource removeAllObjects];
  42. _tabContentView.delegate = self;
  43. for (int i = 0; i < 2 ; i++) {
  44. FwzBaseView *contentView = [[FwzBaseView alloc] initWithFrame:CGRectMake(i*kGXScreenWidth,0, kGXScreenWidth,CGRectGetHeight(self.frame) - CGRectGetHeight(self.channelScroll.frame)) channel:i ChannelId:0];
  45. contentView.artModel = self.model;
  46. contentView.waitModel = self.waitModel;
  47. contentView.delegate = self;
  48. contentView.tag = i;
  49. [contentView renderUIWithInfoChannelId:i withFrame:CGRectMake(i*kGXScreenWidth,0, kGXScreenWidth,CGRectGetHeight(self.frame) - CGRectGetHeight(self.channelScroll.frame))];
  50. [contentView reloadData];
  51. [_tabContentView addSubview:contentView];
  52. [_subSource addObject:contentView];
  53. }
  54. }
  55. - (void)loadDataArray:(NSMutableArray *)modelArr withWaitWorkArray:(NSMutableArray *)waitArray withChannelArray:(NSMutableArray *)channelArray{
  56. // 刷新顶部频道条
  57. [self.channelScroll setChannelArray:channelArray];
  58. [_tabContentView removeAllSubviews];
  59. [_subSource removeAllObjects];
  60. NSLog(@"MyTableView - loadDataArray首页数据%@",modelArr[0]);
  61. _tabContentView.contentSize = CGSizeMake(SCREEN_WIDTH * channelArray.count, 0);
  62. for (int i = 0; i < channelArray.count ; i++) {
  63. ChannelModel *tmpModel = channelArray[i];
  64. FwzBaseView *contentView = [[FwzBaseView alloc] initWithFrame:CGRectMake(i*kGXScreenWidth,0, kGXScreenWidth,CGRectGetHeight(self.frame) - CGRectGetHeight(self.channelScroll.frame)) channel:i ChannelId:tmpModel.Id];
  65. contentView.artModel = self.model;
  66. contentView.waitModel = self.waitModel;
  67. contentView.delegate = self;
  68. contentView.tag = i;
  69. [contentView renderUIWithInfoChannelId:i withFrame:CGRectMake(i*kGXScreenWidth,0, kGXScreenWidth,CGRectGetHeight(self.frame) - CGRectGetHeight(self.channelScroll.frame))];
  70. [contentView reloadData];
  71. [_tabContentView addSubview:contentView];
  72. [_subSource addObject:contentView];
  73. }
  74. }
  75. // 初始化
  76. - (instancetype)initWithTabMyConfigArray:(NSArray<ChannelModel *> *)tabConfigarray {
  77. NSLog(@"tabconfigarray:%lu",(unsigned long)tabConfigarray.count);
  78. if (self = [super initWithFrame:CGRectZero]) {
  79. self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - kNavigationHeight - kTabBarHeight - 9);
  80. // 上面的scrollView
  81. [self.channelScroll setChannelArray:tabConfigarray];
  82. [self addSubview:self.channelScroll];
  83. //下面的scrollView
  84. _tabContentView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,self.channelScroll.height, SCREEN_WIDTH, CGRectGetHeight(self.frame) - CGRectGetHeight(self.channelScroll.frame))];
  85. _tabContentView.pagingEnabled = YES;
  86. _tabContentView.bounces = NO;
  87. _tabContentView.showsHorizontalScrollIndicator = NO;
  88. _tabContentView.contentSize = CGSizeMake(SCREEN_WIDTH * (tabConfigarray.count < 1 ? 2 : tabConfigarray.count), 0);
  89. [self addSubview:_tabContentView];
  90. WEAKSELF
  91. // self.channelScroll.buttonBlock = ^{
  92. // STRONGSELF
  93. // if ([strongSelf.delegate respondsToSelector:@selector(didClickAddButtonChannel:)]) {
  94. // [strongSelf.delegate didClickAddButtonChannel:strongSelf.index];
  95. // }
  96. // };
  97. }
  98. return self;
  99. }
  100. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
  101. CGFloat offSetX = scrollView.contentOffset.x;
  102. NSInteger pageNum = offSetX / SCREEN_WIDTH;
  103. // [self.channelScroll setItemSelected:pageNum];
  104. }
  105. - (HorizonScroll *)channelScroll {
  106. if (!_channelScroll) {
  107. _channelScroll = [[HorizonScroll alloc] initWithFrame:CGRectMake(0, 0, kGXScreenWidth, 45)];
  108. _channelScroll.backgroundColor = [UIColor whiteColor];
  109. // _channelScroll.delegate = self;
  110. }
  111. return _channelScroll;
  112. }
  113. - (void)channelChange:(NSInteger)channelId{
  114. self.tabContentView.contentOffset = CGPointMake((channelId - 10000) * SCREEN_WIDTH, 0);
  115. FwzBaseView *baseView = (FwzBaseView *)[self.tabContentView viewWithTag:channelId];
  116. [baseView.tableView.mj_header beginRefreshing];
  117. }
  118. - (void)didClickAddButtonChannel:(ChannelModel *)channelModel andWith:(Item *)documentModel{
  119. if ([self.delegate respondsToSelector:@selector(didClickChanageChannel:andWith:)]) {
  120. [self.delegate didClickChanageChannel:channelModel andWith:documentModel];
  121. }
  122. }
  123. - (void)didClickWaitWorkChannel:(ChannelModel *)channelModel andWith:(HomeWaitWorkModel *)documentModel{
  124. if ([self.delegate respondsToSelector:@selector(didClickWaitWorkChannnel:andWith:)]) {
  125. [self.delegate didClickWaitWorkChannnel:channelModel andWith:documentModel];
  126. }
  127. }
  128. - (void)didCloseAddButtonChannel:(ChannelModel *)channelModel andWith:(Item *)documentModel{
  129. if ([self.delegate respondsToSelector:@selector(didCloseChannel:andWith:)]) {
  130. [self.delegate didCloseChannel:channelModel andWith:documentModel];
  131. }
  132. }
  133. #pragma mark - setter
  134. - (NSIndexPath *)index{
  135. if (!_index) {
  136. _index = [[NSIndexPath alloc] init];
  137. }
  138. return _index;
  139. }
  140. @end