HomeBigshotVC.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // HomeBigshotVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/6/23.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "HomeBigshotVC.h"
  9. #import "HomeSubModel.h"
  10. #import "HomeSubItemModel.h"
  11. #import "HomeBigshotCell.h"
  12. #import "BookTeacherDetailVC.h"
  13. #import "BookWCDetailVC.h"
  14. #import "BookListenVC.h"
  15. #import "BookListDetailVC.h"
  16. #import "IndexMoreVC.h"
  17. #import "HomeSCDetailVC.h"
  18. @interface HomeBigshotVC ()<UITableViewDelegate,UITableViewDataSource>
  19. @property (nonatomic, strong) UITableView * tableView;
  20. @property (nonatomic, strong) NSMutableArray * dataSource;
  21. @end
  22. @implementation HomeBigshotVC
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. [self.view addSubview:self.tableView];
  26. self.tableView.delegate = self;
  27. self.tableView.dataSource = self;
  28. [self getData];
  29. }
  30. - (void)setHeight:(CGFloat)height
  31. {
  32. [self.tableView setFrame:CGRectMake(0, 0, SCREEN_WIDTH, height - 45)];
  33. }
  34. - (UITableView *)tableView
  35. {
  36. if (!_tableView) {
  37. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  38. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  39. _tableView.showsVerticalScrollIndicator = NO;
  40. }
  41. return _tableView;
  42. }
  43. - (NSMutableArray *)dataSource
  44. {
  45. if (!_dataSource) {
  46. _dataSource = [NSMutableArray array];
  47. }
  48. return _dataSource;
  49. }
  50. - (void)getData
  51. {
  52. WS(weakSelf);
  53. [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_PAGE_CATHEDRA) parameters:@{@"StyleCss":self.style,@"Page":@(1),@"PerPage":@20} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  54. NSLog(@"%@",responseObject);
  55. if ([responseObject isKindOfClass:[NSArray class]]) {
  56. for (NSDictionary * dict in responseObject) {
  57. HomeSubModel *model = [HomeSubModel modelWithDictionary:dict];
  58. [weakSelf.dataSource addObject:model];
  59. }
  60. }
  61. dispatch_async(dispatch_get_main_queue(), ^{
  62. [weakSelf.tableView reloadData];
  63. });
  64. } failure:^(NSError * _Nonnull error) {
  65. }];
  66. }
  67. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  68. {
  69. return 1;
  70. }
  71. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  72. {
  73. return self.dataSource.count;
  74. }
  75. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  76. {
  77. return UITableViewAutomaticDimension;
  78. }
  79. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  80. {
  81. WS(weakSelf);
  82. HomeSubModel *model = self.dataSource[indexPath.row];
  83. if (indexPath.row == 0) {
  84. HomeBigshotCell * cell = [HomeBigshotCell configCell0:tableView indexPath:indexPath];
  85. [cell setDatatype:0 model:model];
  86. cell.ClickItemBlock = ^(HomeSubItemModel * _Nonnull pmodel) {
  87. [weakSelf pushVC:pmodel];
  88. };
  89. return cell;
  90. }else{
  91. HomeBigshotCell * cell = [HomeBigshotCell configCell1:tableView indexPath:indexPath];
  92. [cell setDatatype:1 model:model];
  93. cell.ClickItemBlock = ^(HomeSubItemModel * _Nonnull pmodel) {
  94. [weakSelf pushVC:pmodel];
  95. };
  96. return cell;
  97. }
  98. }
  99. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  100. {
  101. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  102. }
  103. - (void)pushVC:(HomeSubItemModel *)model
  104. {
  105. switch ((CollectModelType)model.MediaType) {
  106. case CollectModel_StoreBook:
  107. {
  108. BookListDetailVC * vc = [BookListDetailVC initBookListDetailVC];
  109. vc.Id = model.Id;
  110. [self.navigationController pushViewController:vc animated:YES];
  111. }
  112. break;
  113. case CollectModel_StoreVideo:
  114. {
  115. BookWCDetailVC * vc = [BookWCDetailVC initBookWCDetailVC];
  116. vc.Id = model.Id;
  117. [self.navigationController pushViewController:vc animated:YES];
  118. }
  119. break;
  120. case CollectModel_StoreSound:
  121. {
  122. BookListenVC * vc = [BookListenVC initBookListenVC];
  123. vc.Id = model.Id;
  124. vc.MediaType = MediaMusicType;
  125. [self.navigationController pushViewController:vc animated:YES];
  126. }
  127. break;
  128. case CollectModel_Teacher:
  129. {
  130. BookTeacherDetailVC * vc = [BookTeacherDetailVC initBookTeacherDetailVC];
  131. vc.Id = model.Id;
  132. [self.navigationController pushViewController:vc animated:YES];
  133. }
  134. break;
  135. case CollectModel_Organization:
  136. {
  137. HomeSCDetailVC * vc = [[HomeSCDetailVC alloc] init];
  138. vc.Id = model.Id;
  139. [self.navigationController pushViewController:vc animated:YES];
  140. }
  141. break;
  142. case CollectModel_MediaAritle:
  143. {
  144. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  145. vc.type = CollectModel_MediaAritle;
  146. vc.Id = model.Id;
  147. [self.navigationController pushViewController:vc animated:YES];
  148. }
  149. break;
  150. default:
  151. {
  152. }
  153. break;
  154. }
  155. }
  156. @end