123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- //
- // KXTeachViewController.m
- // CAISHEN
- //
- // Created by kuxuan on 2017/11/1.
- // Copyright © 2017年 kuxuan. All rights reserved.
- //
- #import "KXTeachViewController.h"
- #import "KXTeachCycleView.h"
- #import "KXTeachCollectionViewCell.h"
- #import "KXNewsWebViewController.h"
- #import "KXCarLoancalViewController.h"
- @interface KXTeachViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,KXTeachCycleViewDelegate>
- @property (nonatomic,strong)KXTeachCycleView *teachCycle;
- @property (nonatomic,strong)UICollectionView *collectionView;
- @property (nonatomic,strong)NSMutableArray *bannnerArray;
- @property (nonatomic,strong)NSMutableArray *dataSource;
- @end
- @implementation KXTeachViewController
- {
- UIView *headerView;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.view.backgroundColor = [UIColor whiteColor];
- [self createCollectionView];
- [self requestDataSource];
- }
- - (void)createCollectionView
- {
- self.name = @"攻略";
- headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 250)];
- headerView.backgroundColor = [UIColor whiteColor];
-
- UILabel *teachLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
- teachLabel.text = @"";
- teachLabel.textColor = [UIColor titleColor];
- teachLabel.font = FONT_SYS(16);
- teachLabel.textAlignment = NSTextAlignmentLeft;
- [headerView addSubview:teachLabel];
-
- self.teachCycle = [[KXTeachCycleView alloc]initWithFrame:CGRectMake(0, 30, SCREEN_WIDTH - 15, 160)];
- self.teachCycle.delegate = self;
- [headerView addSubview:self.teachCycle];
-
- UILabel *grayLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 210, SCREEN_WIDTH, 5)];
- grayLabel.backgroundColor = [UIColor colorWithWhite:0 alpha:0.05];
- [headerView addSubview:grayLabel];
-
- UILabel *programLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 220, 100, 20)];
- programLabel.text = @"理财攻略";
- programLabel.textColor = [UIColor titleColor];
- programLabel.font = FONT_SYS(16);
- programLabel.textAlignment = NSTextAlignmentLeft;
- [headerView addSubview:programLabel];
-
- UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
- flowLayout.itemSize = CGSizeMake((SCREEN_WIDTH - 75)/4.0, 140*SCREEN_MUTI);
- flowLayout.minimumLineSpacing = 10;
- flowLayout.minimumInteritemSpacing = 15;
- flowLayout.headerReferenceSize = CGSizeMake(SCREEN_WIDTH, 250);
- self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NavHeight - TabbarHeight) collectionViewLayout:flowLayout];
- self.collectionView.contentInset = UIEdgeInsetsMake(0, 15, 0, 15);
- [self.collectionView registerClass:[KXTeachCollectionViewCell class] forCellWithReuseIdentifier:@"teach"];
- self.collectionView.backgroundColor = [UIColor whiteColor];
- self.collectionView.delegate = self;
- self.collectionView.dataSource = self;
- [self.view addSubview: self.collectionView];
- [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"UICollectionViewHeader"];
- }
- #pragma mark 请求数据
- -(void)requestDataSource
- {
- NSString *urlString=[NSString stringWithFormat:@"%@/information/getinformationsbypackage",URL];
- NSDictionary *paraDict=@{@"package_id":@"package_1",@"classification_id":@"贷款",@"page":@(1)};
-
- [KXHTTP post:urlString params:paraDict success:^(id json) {
-
- NSMutableArray *bannerImageArray=[NSMutableArray arrayWithCapacity:0];
- if (self.bannnerArray.count==0) {
- for (NSDictionary *dict in json[@"ios_teach_banner"]) {
- [self.bannnerArray addObject:dict];
- [bannerImageArray addObject:dict[@"thumbnail"]];
- }
- _teachCycle.cycleArray=bannerImageArray;
- }
-
- NSArray *array=[NSArray yy_modelArrayWithClass:[KXNewsModel class] json:[json[@"listdata"] valueForKey:@"data"]];
-
- for (KXNewsModel *model in array) {
- [self.dataSource addObject:model];
- }
-
- [self.collectionView reloadData];
-
- } failure:^(NSError *error) {
-
- }];
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
- {
- return self.dataSource.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- KXTeachCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"teach" forIndexPath:indexPath];
- KXNewsModel *model = self.dataSource[indexPath.item];
- cell.newsModel = model;
- return cell;
- }
- - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
- {
-
- NSString *CellIdentifier = @"UICollectionViewHeader";
- //从缓存中获取 Headercell
- UICollectionReusableView *cell = (UICollectionReusableView *)[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:CellIdentifier forIndexPath:indexPath];
- [cell addSubview:headerView];
- return cell;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
- {
- // KXNewsModel *model=self.dataSource[indexPath.item];
- //
- // KXNewsWebViewController *web=[[KXNewsWebViewController alloc]init];
- //
- // web.webID=model.Id;
- //
- // [self.navigationController pushViewController:web animated:YES];
- KXCarLoancalViewController *carvc = [[KXCarLoancalViewController alloc]init];
- [self.navigationController pushViewController:carvc animated:YES];
-
- }
- #pragma mark -----------------KXTeachCycleViewDelegate-----------
- -(void)clickScrollViewItemWithIndex:(NSInteger)index
- {
- NSDictionary *dic=self.bannnerArray[index];
-
- KXNewsWebViewController *web=[[KXNewsWebViewController alloc]init];
-
- web.webID=dic[@"id"];
-
- [self.navigationController pushViewController:web animated:YES];
-
- }
- -(NSMutableArray *)bannnerArray
- {
- if (!_bannnerArray) {
- _bannnerArray=[[NSMutableArray alloc]init];
- }
- return _bannnerArray;
- }
- - (NSMutableArray *)dataSource
- {
- if (!_dataSource) {
- _dataSource = [[NSMutableArray alloc]init];
- }
- return _dataSource;
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #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
|