HomeDayGoodArticeVC.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // HomeDayGoodArticeVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/6/23.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "HomeDayGoodArticeVC.h"
  9. #import "HomeSubModel.h"
  10. #import "HomeSubItemModel.h"
  11. #import "BookSubArticeCell.h"
  12. @interface HomeDayGoodArticeVC ()<UITableViewDelegate,UITableViewDataSource>
  13. @property (nonatomic, strong) UITableView * tableView;
  14. @property (nonatomic, strong) NSMutableArray * dataSource;
  15. @property (nonatomic, assign) NSInteger currentPage;
  16. @property (nonatomic, assign) NSInteger Total;
  17. @end
  18. @implementation HomeDayGoodArticeVC
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. [self.view addSubview:self.tableView];
  22. self.tableView.delegate = self;
  23. self.tableView.dataSource = self;
  24. self.currentPage = 1;
  25. self.Total = 0;
  26. WS(weakSelf);
  27. self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  28. [weakSelf footerRefresh];
  29. }];
  30. [self headRefresh];
  31. }
  32. - (void)setHeight:(CGFloat)height
  33. {
  34. [self.tableView setFrame:CGRectMake(0, 0, SCREEN_WIDTH, height - 45)];
  35. }
  36. - (UITableView *)tableView
  37. {
  38. if (!_tableView) {
  39. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  40. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  41. _tableView.showsVerticalScrollIndicator = NO;
  42. }
  43. return _tableView;
  44. }
  45. - (NSMutableArray *)dataSource
  46. {
  47. if (!_dataSource) {
  48. _dataSource = [NSMutableArray array];
  49. }
  50. return _dataSource;
  51. }
  52. - (void)headRefresh{
  53. self.currentPage = 1;
  54. self.Total = 1;
  55. [self.dataSource removeAllObjects];
  56. [self getData];
  57. }
  58. - (void)footerRefresh{
  59. self.currentPage += 1;
  60. if (self.Total == self.dataSource.count) {
  61. self.currentPage --;
  62. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  63. self.tableView.mj_footer.hidden = YES;
  64. return ;
  65. }
  66. [self getData];
  67. }
  68. - (void)getData
  69. {
  70. WS(weakSelf);
  71. [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_PAGE_GooDText) parameters:@{@"StyleCss":self.style,@"Page":@(self.currentPage),@"PerPage":@20} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  72. NSLog(@"%@",responseObject);
  73. if ([responseObject isKindOfClass:[NSDictionary class]]) {
  74. HomeSubModel *model = [HomeSubModel modelWithDictionary:responseObject];
  75. for (NSDictionary * dict in model.Items) {
  76. HomeSubItemModel *smodel = [HomeSubItemModel modelWithDictionary:dict];
  77. [weakSelf.dataSource addObject:smodel];
  78. }
  79. weakSelf.Total = model.Total;
  80. }
  81. [weakSelf.tableView.mj_footer endRefreshing];
  82. dispatch_async(dispatch_get_main_queue(), ^{
  83. [weakSelf.tableView reloadData];
  84. });
  85. } failure:^(NSError * _Nonnull error) {
  86. [weakSelf.tableView.mj_footer endRefreshing];
  87. }];
  88. }
  89. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  90. {
  91. return 1;
  92. }
  93. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  94. {
  95. return self.dataSource.count;
  96. }
  97. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  98. {
  99. return UITableViewAutomaticDimension;
  100. }
  101. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  102. {
  103. HomeSubItemModel *model = self.dataSource[indexPath.row];
  104. BookSubArticeCell * cell = [BookSubArticeCell configCell:tableView indexPath:indexPath];
  105. [cell setDataWithModel:model];
  106. return cell;
  107. }
  108. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  109. {
  110. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  111. HomeSubItemModel *model = self.dataSource[indexPath.row];
  112. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  113. vc.Id = model.Id;
  114. vc.type = model.MediaType;
  115. [self.navigationController pushViewController:vc animated:YES];
  116. }
  117. @end