ThirdViewController.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // ThirdViewController.m
  3. // PersonalCenter
  4. //
  5. // Created by Arch on 2017/6/16.
  6. // Copyright © 2017年 mint_bin. All rights reserved.
  7. //
  8. #import "ThirdViewController.h"
  9. #import "HomeSubItemModel.h"
  10. #import "IndexAllCell.h"
  11. #import "MoveViewController.h"
  12. #import "BookTeacherDetailVC.h"
  13. #import "BookWCDetailVC.h"
  14. #import "BookListenVC.h"
  15. #import "BookListDetailVC.h"
  16. #import "IndexMoreVC.h"
  17. static NSString *const ThirdViewControllerCollectionViewCellIdentifier = @"ThirdViewControllerCollectionViewCell";
  18. @interface ThirdViewController () <UITableViewDelegate, UITableViewDataSource>
  19. @property (nonatomic, strong) NSMutableArray *dataSource;
  20. @property(nonatomic, strong) UITableView *tableView;
  21. @end
  22. @implementation ThirdViewController
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. self.view.backgroundColor = UIColorHex(0xF8F9FB);
  26. [self creatTableView];
  27. }
  28. - (NSMutableArray *)dataSource
  29. {
  30. if (!_dataSource) {
  31. _dataSource = [NSMutableArray array];
  32. }
  33. return _dataSource;
  34. }
  35. - (void)creatTableView {
  36. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 10, SCREEN_WIDTH, SCREEN_HEIGHT - NAVH - 150)];
  37. _tableView.delegate = self;
  38. _tableView.dataSource = self;
  39. _tableView.showsVerticalScrollIndicator = NO;
  40. _tableView.showsHorizontalScrollIndicator = NO;
  41. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  42. _tableView.rowHeight = 50;
  43. [self.view addSubview:_tableView];
  44. }
  45. - (void)setDataArray:(NSArray *)array
  46. {
  47. [self.dataSource removeAllObjects];
  48. for (NSDictionary *dict in array) {
  49. NSMutableArray * addArray = [NSMutableArray array];
  50. IndexAllModel * model = [IndexAllModel modelWithDictionary:dict];
  51. for (NSDictionary * subDict in model.Items) {
  52. HomeSubItemModel * submodel = [HomeSubItemModel modelWithDictionary:subDict];
  53. [addArray addObject:submodel];
  54. }
  55. model.Items = addArray.mutableCopy;
  56. [self.dataSource addObject:model];
  57. }
  58. [self.tableView reloadData];
  59. }
  60. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  61. {
  62. return 1;
  63. }
  64. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  65. {
  66. return self.dataSource.count;
  67. }
  68. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  69. {
  70. return UITableViewAutomaticDimension;
  71. }
  72. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  73. {
  74. WS(weakSelf);
  75. IndexAllModel *model = self.dataSource[indexPath.row];
  76. IndexAllCell * cell = [IndexAllCell configCell1:tableView indexPath:indexPath];
  77. [cell setDataWithModel:model];
  78. cell.ClickRowBlock = ^(CollectModelType type, NSInteger Id) {
  79. [weakSelf pushVC:type Id:Id];
  80. };
  81. return cell;
  82. }
  83. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  84. {
  85. HomeSubItemModel * model = self.dataSource[indexPath.row];
  86. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  87. BookTeacherDetailVC * vc = [BookTeacherDetailVC initBookTeacherDetailVC];
  88. vc.Id = model.Id;
  89. [self.navigationController pushViewController:vc animated:YES];
  90. }
  91. - (void)pushVC:(CollectModelType)type Id:(NSInteger)Id
  92. {
  93. switch (type) {
  94. case CollectModel_StoreBook:
  95. {
  96. BookListDetailVC * vc = [BookListDetailVC initBookListDetailVC];
  97. vc.Id = Id;
  98. [self.navigationController pushViewController:vc animated:YES];
  99. }
  100. break;
  101. case CollectModel_StoreVideo:
  102. {
  103. BookWCDetailVC * vc = [BookWCDetailVC initBookWCDetailVC];
  104. vc.Id = Id;
  105. [self.navigationController pushViewController:vc animated:YES];
  106. }
  107. break;
  108. case CollectModel_StoreSound:
  109. {
  110. BookListenVC * vc = [BookListenVC initBookListenVC];
  111. vc.Id = Id;
  112. vc.MediaType = MediaMusicType;
  113. [self.navigationController pushViewController:vc animated:YES];
  114. }
  115. break;
  116. case CollectModel_Teacher:
  117. {
  118. BookTeacherDetailVC * vc = [BookTeacherDetailVC initBookTeacherDetailVC];
  119. vc.Id = Id;
  120. [self.navigationController pushViewController:vc animated:YES];
  121. }
  122. break;
  123. case CollectModel_Organization:
  124. {
  125. }
  126. break;
  127. default:
  128. {
  129. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  130. vc.type = type;
  131. vc.Id = Id;
  132. [self.navigationController pushViewController:vc animated:YES];
  133. }
  134. break;
  135. }
  136. }
  137. @end