HomeDayGoodArticeVC.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. [weakSelf.tableView.mj_footer endRefreshing];
  74. if ([responseObject isKindOfClass:[NSDictionary class]]) {
  75. HomeSubModel *model = [HomeSubModel modelWithDictionary:responseObject];
  76. for (NSDictionary * dict in model.Items) {
  77. HomeSubItemModel *smodel = [HomeSubItemModel modelWithDictionary:dict];
  78. [weakSelf.dataSource addObject:smodel];
  79. }
  80. weakSelf.Total = model.Total;
  81. if (weakSelf.Total == weakSelf.dataSource.count) {
  82. [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
  83. weakSelf.tableView.mj_footer.hidden = YES;
  84. }
  85. }
  86. dispatch_async(dispatch_get_main_queue(), ^{
  87. [weakSelf.tableView reloadData];
  88. });
  89. } failure:^(NSError * _Nonnull error) {
  90. [weakSelf.tableView.mj_footer endRefreshing];
  91. }];
  92. }
  93. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  94. {
  95. return 1;
  96. }
  97. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  98. {
  99. return self.dataSource.count;
  100. }
  101. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  102. {
  103. return UITableViewAutomaticDimension;
  104. }
  105. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  106. {
  107. HomeSubItemModel *model = self.dataSource[indexPath.row];
  108. BookSubArticeCell * cell = [BookSubArticeCell configCell:tableView indexPath:indexPath];
  109. [cell setDataWithModel:model];
  110. return cell;
  111. }
  112. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  113. {
  114. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  115. HomeSubItemModel *model = self.dataSource[indexPath.row];
  116. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  117. vc.Id = model.Id;
  118. vc.type = model.MediaType;
  119. [self.navigationController pushViewController:vc animated:YES];
  120. }
  121. @end