OnlineLearningViewController.m 3.05 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
{
曹云霄's avatar
曹云霄 committed
34
    self.onlineLearningFlowLayout.itemSize = CGSizeMake((ScreenWidth-60)/3.0, ((ScreenWidth-60)/3.0)*0.9);
35
    self.onlineLearningFlowLayout.sectionInset = UIEdgeInsetsMake(20, 20, 20, 20);
曹云霄's avatar
曹云霄 committed
36 37
    self.onlineLearningFlowLayout.minimumLineSpacing = 10;
    self.onlineLearningFlowLayout.minimumInteritemSpacing = 10;
曹云霄's avatar
曹云霄 committed
38 39
}

40 41 42
#pragma mark - 学习模块数据
- (void)getLearningModuleData
{
43
  WS(weakSelf);
44
  [XBLoadingView showHUDViewWithDefault];;
曹云霄's avatar
曹云霄 committed
45
  [HTTP networkWithDictionaryRequestWithURL:SERVERREQUESTURL(STUDYTYPES) withRequestType:ONE withParameter:nil withReturnValueBlock:^(id returnValue) {
46
      
47
      [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
48
      if (RESULT(returnValue)) {
曹云霄's avatar
曹云霄 committed
49
          StudyTypeResponse *response = [[StudyTypeResponse alloc]initWithDictionary:RESPONSE(returnValue) error:nil];
50
          [weakSelf.studyTypeArray addObjectsFromArray:response.types];
51
      }else {
52
          [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
53 54 55
      }
      [weakSelf.onlineLearningCollectionView reloadData];
      
56
  }withFailureBlock:^(NSError *error) {
57
      [XBLoadingView hideHUDViewWithDefault];
58
      [XBLoadingView showHUDViewWithText:error.localizedDescription];
59
  }];
60
}
曹云霄's avatar
曹云霄 committed
61

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

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

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


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

@end