HomeSchoolVC.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // HomeSchoolVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/6/23.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "HomeSchoolVC.h"
  9. #import "HomeSubItemModel.h"
  10. #import "HomeSchoolCell.h"
  11. #import "HomeSCDetailVC.h"
  12. @interface HomeSchoolVC ()<UITableViewDelegate,UITableViewDataSource>
  13. @property (nonatomic, strong) UITableView * tableView;
  14. @property (nonatomic, strong) NSMutableArray * dataSource;
  15. @end
  16. @implementation HomeSchoolVC
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. [self.view addSubview:self.tableView];
  20. self.tableView.delegate = self;
  21. self.tableView.dataSource = self;
  22. [self getData];
  23. }
  24. - (void)setHeight:(CGFloat)height
  25. {
  26. [self.tableView setFrame:CGRectMake(0, 0, SCREEN_WIDTH, height - 45)];
  27. }
  28. - (UITableView *)tableView
  29. {
  30. if (!_tableView) {
  31. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  32. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  33. _tableView.showsVerticalScrollIndicator = NO;
  34. }
  35. return _tableView;
  36. }
  37. - (NSMutableArray *)dataSource
  38. {
  39. if (!_dataSource) {
  40. _dataSource = [NSMutableArray array];
  41. }
  42. return _dataSource;
  43. }
  44. - (void)getData
  45. {
  46. WS(weakSelf);
  47. [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_PAGE_Press) parameters:@{@"Page":@(1),@"PerPage":@20} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  48. NSLog(@"%@",responseObject);
  49. if ([responseObject isKindOfClass:[NSDictionary class]]) {
  50. for (NSDictionary * dict in responseObject[@"Items"]) {
  51. HomeSubItemModel *model = [HomeSubItemModel modelWithDictionary:dict];
  52. [weakSelf.dataSource addObject:model];
  53. }
  54. }
  55. dispatch_async(dispatch_get_main_queue(), ^{
  56. [weakSelf.tableView reloadData];
  57. });
  58. } failure:^(NSError * _Nonnull error) {
  59. }];
  60. }
  61. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  62. {
  63. return 1;
  64. }
  65. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  66. {
  67. return self.dataSource.count;
  68. }
  69. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  70. {
  71. return UITableViewAutomaticDimension;
  72. }
  73. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  74. {
  75. HomeSubItemModel *model = self.dataSource[indexPath.row];
  76. HomeSchoolCell * cell = [HomeSchoolCell configCell0:tableView indexPath:indexPath];
  77. if (indexPath.row > 0) {
  78. cell.topView.hidden = YES;
  79. cell.height.constant = 0.f;
  80. }
  81. cell.lineV.hidden = NO;
  82. [cell setDataModel:model];
  83. return cell;
  84. }
  85. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  86. {
  87. HomeSubItemModel *model = self.dataSource[indexPath.row];
  88. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  89. HomeSCDetailVC * vc = [[HomeSCDetailVC alloc] init];
  90. vc.Id = model.Id;
  91. vc.hidesBottomBarWhenPushed = YES;
  92. [self.navigationController pushViewController:vc animated:YES];
  93. }
  94. @end