123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- //
- // MyTableView.m
- // 老淘宝详情
- //
- // Created by Kobe24 on 2018/3/8.
- // Copyright © 2018年 SYD. All rights reserved.
- //
- #import "MyTableView.h"
- #import "HorizonScroll.h"
- #import "ChannelModel.h"
- #import "FwzBaseView.h"
- @interface MyTableView ()<UIScrollViewDelegate>
- @property (nonatomic, strong) UIScrollView *tabContentView;
- @property (nonatomic, strong) HorizonScroll *channelScroll;
- @property (nonatomic, strong) NSMutableArray *subSource;
- @end
- @implementation MyTableView
- - (void)scrollTop{
- for (UIView * view in self.tabContentView.subviews) {
- for (UIView * subview in view.subviews) {
- if ([subview isKindOfClass:[UITableView class]]) {
- UITableView * tabview = (UITableView *)subview;
- [tabview scrollToTop];
- }
- }
- }
- [self.tabContentView scrollToTop];
- }
- - (void)loadDataWithIndex:(NSInteger)index {
- FwzBaseView *baseView = (FwzBaseView *)[self.tabContentView viewWithTag:index];
- [baseView reloadData];
- }
- - (NSMutableArray *)subSource {
- if (_subSource == nil) {
- _subSource = [[NSMutableArray alloc] init];
- }
- return _subSource;
- }
- - (void)loadData:(HomeArticleModel *)model withWaitWorkArray:(TDWaitWorkModel *)waitModel{
- NSLog(@"MyTableView - loadData首页数据%@",model);
- [_subSource removeAllObjects];
- _tabContentView.delegate = self;
- for (int i = 0; i < 2 ; i++) {
- FwzBaseView *contentView = [[FwzBaseView alloc] initWithFrame:CGRectMake(i*kGXScreenWidth,0, kGXScreenWidth,CGRectGetHeight(self.frame) - CGRectGetHeight(self.channelScroll.frame)) channel:i ChannelId:0];
- contentView.artModel = self.model;
- contentView.waitModel = self.waitModel;
- contentView.delegate = self;
- contentView.tag = i;
- [contentView renderUIWithInfoChannelId:i withFrame:CGRectMake(i*kGXScreenWidth,0, kGXScreenWidth,CGRectGetHeight(self.frame) - CGRectGetHeight(self.channelScroll.frame))];
- [contentView reloadData];
- [_tabContentView addSubview:contentView];
- [_subSource addObject:contentView];
- }
- }
- - (void)loadDataArray:(NSMutableArray *)modelArr withWaitWorkArray:(NSMutableArray *)waitArray withChannelArray:(NSMutableArray *)channelArray{
- // 刷新顶部频道条
- [self.channelScroll setChannelArray:channelArray];
- [_tabContentView removeAllSubviews];
- [_subSource removeAllObjects];
- NSLog(@"MyTableView - loadDataArray首页数据%@",modelArr[0]);
- _tabContentView.contentSize = CGSizeMake(SCREEN_WIDTH * channelArray.count, 0);
- for (int i = 0; i < channelArray.count ; i++) {
- ChannelModel *tmpModel = channelArray[i];
- FwzBaseView *contentView = [[FwzBaseView alloc] initWithFrame:CGRectMake(i*kGXScreenWidth,0, kGXScreenWidth,CGRectGetHeight(self.frame) - CGRectGetHeight(self.channelScroll.frame)) channel:i ChannelId:tmpModel.Id];
- contentView.artModel = self.model;
- contentView.waitModel = self.waitModel;
- contentView.delegate = self;
- contentView.tag = i;
- [contentView renderUIWithInfoChannelId:i withFrame:CGRectMake(i*kGXScreenWidth,0, kGXScreenWidth,CGRectGetHeight(self.frame) - CGRectGetHeight(self.channelScroll.frame))];
- [contentView reloadData];
- [_tabContentView addSubview:contentView];
- [_subSource addObject:contentView];
- }
- }
- // 初始化
- - (instancetype)initWithTabMyConfigArray:(NSArray<ChannelModel *> *)tabConfigarray {
- NSLog(@"tabconfigarray:%lu",(unsigned long)tabConfigarray.count);
- if (self = [super initWithFrame:CGRectZero]) {
- self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - kNavigationHeight - kTabBarHeight - 9);
- // 上面的scrollView
- [self.channelScroll setChannelArray:tabConfigarray];
- [self addSubview:self.channelScroll];
- //下面的scrollView
- _tabContentView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,self.channelScroll.height, SCREEN_WIDTH, CGRectGetHeight(self.frame) - CGRectGetHeight(self.channelScroll.frame))];
- _tabContentView.pagingEnabled = YES;
- _tabContentView.bounces = NO;
- _tabContentView.showsHorizontalScrollIndicator = NO;
- _tabContentView.contentSize = CGSizeMake(SCREEN_WIDTH * (tabConfigarray.count < 1 ? 2 : tabConfigarray.count), 0);
- [self addSubview:_tabContentView];
-
- WEAKSELF
- // self.channelScroll.buttonBlock = ^{
- // STRONGSELF
- // if ([strongSelf.delegate respondsToSelector:@selector(didClickAddButtonChannel:)]) {
- // [strongSelf.delegate didClickAddButtonChannel:strongSelf.index];
- // }
- // };
- }
- return self;
- }
- - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
- CGFloat offSetX = scrollView.contentOffset.x;
- NSInteger pageNum = offSetX / SCREEN_WIDTH;
- // [self.channelScroll setItemSelected:pageNum];
- }
- - (HorizonScroll *)channelScroll {
- if (!_channelScroll) {
- _channelScroll = [[HorizonScroll alloc] initWithFrame:CGRectMake(0, 0, kGXScreenWidth, 45)];
- _channelScroll.backgroundColor = [UIColor whiteColor];
- // _channelScroll.delegate = self;
- }
- return _channelScroll;
- }
- - (void)channelChange:(NSInteger)channelId{
- self.tabContentView.contentOffset = CGPointMake((channelId - 10000) * SCREEN_WIDTH, 0);
- FwzBaseView *baseView = (FwzBaseView *)[self.tabContentView viewWithTag:channelId];
- [baseView.tableView.mj_header beginRefreshing];
- }
- - (void)didClickAddButtonChannel:(ChannelModel *)channelModel andWith:(Item *)documentModel{
- if ([self.delegate respondsToSelector:@selector(didClickChanageChannel:andWith:)]) {
- [self.delegate didClickChanageChannel:channelModel andWith:documentModel];
- }
- }
- - (void)didClickWaitWorkChannel:(ChannelModel *)channelModel andWith:(HomeWaitWorkModel *)documentModel{
- if ([self.delegate respondsToSelector:@selector(didClickWaitWorkChannnel:andWith:)]) {
- [self.delegate didClickWaitWorkChannnel:channelModel andWith:documentModel];
- }
- }
- - (void)didCloseAddButtonChannel:(ChannelModel *)channelModel andWith:(Item *)documentModel{
- if ([self.delegate respondsToSelector:@selector(didCloseChannel:andWith:)]) {
- [self.delegate didCloseChannel:channelModel andWith:documentModel];
- }
- }
- #pragma mark - setter
- - (NSIndexPath *)index{
- if (!_index) {
- _index = [[NSIndexPath alloc] init];
- }
- return _index;
- }
- @end
|