BGSystemMsgVC.m 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. //
  2. // BGSystemMsgVC.m
  3. // BuguLive
  4. //
  5. // Created by bugu on 2019/12/16.
  6. // Copyright © 2019 xfg. All rights reserved.
  7. //
  8. #import "BGSystemMsgVC.h"
  9. #import "BGSystemMsgContentCell.h"
  10. #import "BGSystemMsgImageCell.h"
  11. #import "BzoneLogic.h"
  12. #import "YHRefreshTableView.h"
  13. #import "UITableViewCell+HYBMasonryAutoCellHeight.h"
  14. @interface BGSystemMsgVC ()<UITableViewDelegate,UITableViewDataSource,BzoneLogicDelegate>{
  15. int _currentRequestPage; //当前请求页面
  16. BOOL _reCalculate;
  17. }
  18. @property(nonatomic, strong) UITableView *tableView;
  19. @property(nonatomic, strong) NSMutableArray *dataArray;
  20. @property (nonatomic, strong) BzoneLogic *logic;
  21. @end
  22. @implementation BGSystemMsgVC
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. // Do any additional setup after loading the view.
  26. self.title = ASLocalizedString(@"系统消息");
  27. self.logic = [BzoneLogic new];
  28. self.logic.page = 1;
  29. _logic.delegagte = self;
  30. _logic.isGZ = YES;
  31. [_logic loadMsg_ListData];
  32. [self requestDataLoadNew:YES];
  33. [self backBtnWithBlock];
  34. }
  35. - (void)backBtnWithBlock
  36. {
  37. // 返回按钮
  38. self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(onReturnBtnPress) image:@"com_arrow_vc_back" highImage:@"com_arrow_vc_back"];
  39. }
  40. - (void)onReturnBtnPress
  41. {
  42. [self.navigationController popViewControllerAnimated:YES];
  43. }
  44. #pragma mark 初始化变量
  45. - (void)initFWVariables
  46. {
  47. [super initFWVariables];
  48. }
  49. #pragma mark UI创建
  50. - (void)initFWUI
  51. {
  52. [super initFWUI];
  53. [self.view addSubview:self.tableView];
  54. [BGMJRefreshManager refresh:self.tableView target:self headerRereshAction:@selector(refreshHeader) footerRereshAction:@selector(refreshFooter)];
  55. }
  56. #pragma mark - 网络请求
  57. - (void)requestDataLoadNew:(BOOL)loadNew{
  58. YHRefreshType refreshType;
  59. if (loadNew) {
  60. _currentRequestPage = 1;
  61. refreshType = YHRefreshType_LoadNew;
  62. // [self.tableView setNoMoreData:NO];
  63. }
  64. else{
  65. _currentRequestPage ++;
  66. refreshType = YHRefreshType_LoadMore;
  67. }
  68. if (loadNew) {
  69. [self.dataArray removeAllObjects];
  70. }
  71. _logic.page = _currentRequestPage;
  72. [_logic loadMsg_ListData];
  73. }
  74. -(void)requestZoneListDataCompleted
  75. {
  76. [self.tableView reloadData];
  77. [self.tableView.mj_footer endRefreshing];
  78. [self.tableView.mj_header endRefreshing];
  79. self.dataArray = _logic.dataArray;
  80. if(_logic.noHasMore == YES)
  81. {
  82. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  83. }
  84. [BGMJRefreshManager endRefresh:self.tableView];
  85. }
  86. -(void)refreshHeader{
  87. [self requestDataLoadNew:YES];
  88. }
  89. -(void)refreshFooter{
  90. [self requestDataLoadNew:NO];
  91. }
  92. #pragma mark 加载数据
  93. - (void)initFWData
  94. {
  95. [super initFWData];
  96. }
  97. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  98. return 1;
  99. }
  100. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  101. return self.dataArray.count;
  102. }
  103. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  104. // return 100;
  105. BGSystemMsgModel *model = self.dataArray[indexPath.row];
  106. if (model.type.intValue == 1) {
  107. CGFloat height = [BGSystemMsgContentCell hyb_heightForTableView:tableView config:^(UITableViewCell *sourceCell) {
  108. BGSystemMsgContentCell *cell = (BGSystemMsgContentCell *)sourceCell;
  109. cell.model = model;
  110. }];
  111. return height;
  112. }
  113. CGFloat height = [BGSystemMsgImageCell hyb_heightForTableView:tableView config:^(UITableViewCell *sourceCell) {
  114. BGSystemMsgImageCell *cell = (BGSystemMsgImageCell *)sourceCell;
  115. cell.model = model;
  116. }];
  117. return height;
  118. }
  119. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  120. BGSystemMsgModel *model = self.dataArray[indexPath.row];
  121. if (model.type.intValue == 1) {
  122. BGSystemMsgContentCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([BGSystemMsgContentCell class])];
  123. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  124. cell.model = model;
  125. return cell;
  126. }
  127. BGSystemMsgImageCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([BGSystemMsgImageCell class])];
  128. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  129. cell.model = model;
  130. return cell;
  131. }
  132. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  133. //有链接的跳转
  134. BGSystemMsgModel *model = self.dataArray[indexPath.row];
  135. NSString * url = model.link_url;
  136. BGMainWebViewController *tmpController = [BGMainWebViewController webControlerWithUrlStr:url isShowIndicator:YES isShowNavBar:YES isShowBackBtn:YES];
  137. tmpController.navTitleStr = model.title;
  138. [[AppDelegate sharedAppDelegate] pushViewController:tmpController animated:YES];
  139. }
  140. - (void)viewWillAppear:(BOOL)animated {
  141. [super viewWillAppear:animated];
  142. self.navigationController.navigationBarHidden = NO;
  143. }
  144. - (void)viewWillDisappear:(BOOL)animated {
  145. [super viewWillDisappear:animated];
  146. self.navigationController.navigationBarHidden = YES;
  147. }
  148. - (NSMutableArray *)dataArray{
  149. if (!_dataArray) {
  150. _dataArray = [NSMutableArray array];
  151. }
  152. return _dataArray;
  153. }
  154. -(UITableView *)tableView{
  155. if (!_tableView) {
  156. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH -kTopHeight) style:UITableViewStylePlain];
  157. _tableView.delegate = self;
  158. _tableView.dataSource = self;
  159. [_tableView registerClass:[BGSystemMsgContentCell class] forCellReuseIdentifier:NSStringFromClass([BGSystemMsgContentCell class])];
  160. [_tableView registerClass:[BGSystemMsgImageCell class] forCellReuseIdentifier:NSStringFromClass([BGSystemMsgImageCell class])];
  161. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  162. _tableView.tableFooterView = [UIView new];
  163. }
  164. return _tableView;
  165. }
  166. @end