// // ElearningLogVC.m // JSJPCoach // // Created by EchoShacolee on 2018/1/30. // Copyright © 2018年 Danson. All rights reserved. // #import "ElearningLogVC.h" #import "EleOneTableVC.h" #import "EleTwoTableVC.h" #import "EleThreeTableVC.h" #import "EleFourTableVC.h" @interface ElearningLogVC () @property (strong, nonatomic) UISegmentedControl *seg; @property (strong, nonatomic) UIScrollView *mainScrView; @end @implementation ElearningLogVC - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = [NSString stringWithFormat:@"电子教学日志"]; _seg = [[UISegmentedControl alloc]initWithItems:@[@"科一",@"科二",@"科三",@"科四"]]; _seg.frame = CGRectMake(0, kNavOffSet, kSize.width, 40); _seg.selectedSegmentIndex = 0; // _seg.tintColor = COLOR_THEME; [_seg addTarget:self action:@selector(changeTableview) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:_seg]; NSArray *arr = @[@"EleOneTableVC",@"EleTwoTableVC",@"EleThreeTableVC",@"EleFourTableVC"]; _mainScrView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_seg.frame), kSize.width, kSize.height-CGRectGetMaxY(_seg.frame)-kSafeAreaBottomHeight)]; _mainScrView.contentSize = CGSizeMake(kSize.width*arr.count, 0); _mainScrView.pagingEnabled = YES; _mainScrView.showsHorizontalScrollIndicator = NO; _mainScrView.bounces = NO; _mainScrView.delegate = self; [self.view addSubview:_mainScrView]; NSInteger i=0; for (NSString *clsStr in arr) { Class cls = NSClassFromString(clsStr); EleBaseTableVC *vc = [[cls alloc]init]; vc.stuDic = self.stuDic; vc.view.frame = CGRectMake(kSize.width*i++, 0, kSize.width, _mainScrView.height); [self addChildViewController:vc]; [_mainScrView addSubview:vc.view]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)changeTableview{ [_mainScrView setContentOffset:CGPointMake(kSize.width*_seg.selectedSegmentIndex, 0) animated:NO]; } -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ _seg.selectedSegmentIndex = scrollView.contentOffset.x/kSize.width; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end