OnlineLearningViewController.m 3.06 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9
//
//  OnlineLearningViewController.m
//  Lighting
//
//  Created by 曹云霄 on 2016/11/16.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "OnlineLearningViewController.h"
10
#import "OnlineLearningTableViewCell.h"
11
#import "OnlineLearningDetailViewController.h"
曹云霄's avatar
曹云霄 committed
12 13
@interface OnlineLearningViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>

14 15 16 17 18 19

/**
 学习类别
 */
@property (nonatomic,strong) NSMutableArray *studyTypeArray;

曹云霄's avatar
曹云霄 committed
20 21 22 23 24 25 26 27
@end

@implementation OnlineLearningViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setUpCollectionView];
28
    [self getLearningModuleData];
曹云霄's avatar
曹云霄 committed
29 30 31 32 33
}

#pragma mark - UICollectionView
- (void)setUpCollectionView
{
34 35 36 37
    self.onlineLearningFlowLayout.itemSize = CGSizeMake((ScreenWidth-100)/4.0, ((ScreenWidth-100)/4.0-50));
    self.onlineLearningFlowLayout.sectionInset = UIEdgeInsetsMake(20, 20, 20, 20);
    self.onlineLearningFlowLayout.minimumLineSpacing = 20;
    self.onlineLearningFlowLayout.minimumInteritemSpacing = 20;
曹云霄's avatar
曹云霄 committed
38 39
}

40 41 42
#pragma mark - 学习模块数据
- (void)getLearningModuleData
{
43
  WS(weakSelf);
44 45
  [XBLoadingView showHUDViewWithDefault];;
  [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:SERVERREQUESTURL(STUDYTYPES) WithRequestType:ONE WithParameter:nil WithReturnValueBlock:^(id returnValue) {
46
      
47
      [XBLoadingView hideHUDViewWithDefault];
48
      if ([returnValue[@"code"] isEqualToNumber:@0]) {
49 50
          StudyTypeResponse *response = [[StudyTypeResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
          [weakSelf.studyTypeArray addObjectsFromArray:response.types];
51
      }else {
52
          [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
53 54 55
      }
      [weakSelf.onlineLearningCollectionView reloadData];
      
56 57
  }WithFailureBlock:^(NSError *error) {
      [XBLoadingView showHUDViewWithText:error.localizedDescription];
58
  }];
59
}
曹云霄's avatar
曹云霄 committed
60

61 62 63
#pragma mark - <UICollectionViewDelegate,UICollectionViewDataSource>
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
64
    return self.studyTypeArray.count;
65
}
曹云霄's avatar
曹云霄 committed
66

67 68 69
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    OnlineLearningTableViewCell *learningCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"OnlineLearningTableViewCell" forIndexPath:indexPath];
70
    learningCell.studeType = self.studyTypeArray[indexPath.row];
71 72
    return learningCell;
}
曹云霄's avatar
曹云霄 committed
73

74 75 76
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    OnlineLearningDetailViewController *studyDetail = [[[self class] getLearningCenterStoryboardClass]instantiateViewControllerWithIdentifier:@"OnlineLearningDetailViewController"];
77
    studyDetail.studyTypeEntity = self.studyTypeArray[indexPath.row];
78 79
    [self.navigationController pushViewController:studyDetail animated:YES];
}
曹云霄's avatar
曹云霄 committed
80 81


82 83 84 85 86 87 88
#pragma mark - lazy
- (NSMutableArray *)studyTypeArray
{
    if (!_studyTypeArray) {
        _studyTypeArray = [NSMutableArray array];
    }
    return _studyTypeArray;
曹云霄's avatar
曹云霄 committed
89 90 91
}

@end