Base_tbVC.m 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. //
  2. // Base_tbVC.m
  3. // LNManager
  4. //
  5. // Created by EchoShacolee on 2017/4/9.
  6. // Copyright © 2017年 lee. All rights reserved.
  7. //
  8. #import "Base_tbVC.h"
  9. @interface Base_tbVC ()
  10. @end
  11. @implementation Base_tbVC
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. self.view.backgroundColor = KBackGroundColor;
  15. _dataurce = [[NSMutableArray alloc]init];
  16. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kSize.width, kSize.height-SafeAreaBottomHeight)];
  17. _tableView.backgroundColor = KBackGroundColor;
  18. _tableView.dataSource = self;
  19. _tableView.delegate = self;
  20. [self.view addSubview:_tableView];
  21. self.tableView.tableFooterView = [UIView new];
  22. self.holderV = [[HolderView alloc] initWithFrame:_tableView.frame];
  23. [self.holderV freshBlock:^{
  24. if (_block) {
  25. _block();
  26. }
  27. }];
  28. [self.view addSubview:self.holderV];
  29. }
  30. #pragma mark 获取数据
  31. -(void)getDataWithDic:(NSMutableDictionary *)mdic method:(NSString *)method{
  32. //判断网络是否连接
  33. if (![NetworkManager connectedToNetWork]) {
  34. [self showMsgByAlertVCWithString:@"网络连接异常"];
  35. return;
  36. }
  37. [MBProgressHUD hideHUDForView:self.view animated:NO];
  38. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  39. [NetworkManager requestWithMethod:method parameters:mdic type:0 handler:^(NSDictionary *successDic, NSString *failureStr) {
  40. [MBProgressHUD hideHUDForView:self.view animated:YES];
  41. self.holderV.hidden = NO;
  42. if (failureStr) {
  43. [self showMsgByAlertVCWithString:failureStr];
  44. return;
  45. }
  46. if ([successDic[@"code"] isEqualToString:@"1"]) {
  47. [self showMsgByAlertVCWithString:successDic[@"msg"]];
  48. return;
  49. }
  50. _dataurce = successDic[@"body"];
  51. if (_dataurce.count != 0) {
  52. self.holderV.hidden = YES;
  53. }
  54. [self.tableView reloadData];
  55. }];
  56. }
  57. #pragma mark 获取数据2
  58. -(void)getDataWithDic:(NSMutableDictionary *)mdic method:(NSString *)method block:(Block)block{
  59. //判断网络是否连接
  60. if (![NetworkManager connectedToNetWork]) {
  61. [self showMsgByAlertVCWithString:@"网络连接异常"];
  62. return;
  63. }
  64. [MBProgressHUD hideHUDForView:self.view animated:NO];
  65. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  66. [NetworkManager requestWithMethod:method parameters:mdic type:0 handler:^(NSDictionary *successDic, NSString *failureStr) {
  67. [MBProgressHUD hideHUDForView:self.view animated:YES];
  68. self.holderV.hidden = NO;
  69. //判断是否在请求第二页数据
  70. NSString *currentPage = mdic[@"currentPage"];
  71. if (currentPage && ![currentPage isEqualToString:@"1"]) {
  72. self.holderV.hidden = YES;
  73. }
  74. //设置加载状态
  75. _IS_LOADING=NO;
  76. if (failureStr) {
  77. [self showMsgByAlertVCWithString:failureStr];
  78. return;
  79. }
  80. if ([successDic[@"code"] isEqualToString:@"1"]) {
  81. [self showMsgByAlertVCWithString:successDic[@"msg"]];
  82. return;
  83. }
  84. if (block) {
  85. block(successDic);
  86. }
  87. }];
  88. }
  89. #pragma mark 弹出框提示
  90. - (void)showMsgByAlertVCWithString:(NSString *)str{
  91. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:str preferredStyle:UIAlertControllerStyleAlert];
  92. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];
  93. [self presentViewController:alertFind animated:true completion:nil];
  94. }
  95. - (void)showMsgByMBWithString:(NSString *)str{
  96. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  97. hud.mode = MBProgressHUDModeText;
  98. hud.label.text = str;
  99. hud.margin = HUD_MARGIN;
  100. hud.removeFromSuperViewOnHide = YES;
  101. [hud hideAnimated:YES afterDelay:2];
  102. }
  103. #pragma mark 代理方法,具体实现子类完成
  104. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  105. return 0;
  106. }
  107. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  108. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"nouse"];
  109. return cell;
  110. }
  111. - (void)didReceiveMemoryWarning {
  112. [super didReceiveMemoryWarning];
  113. // Dispose of any resources that can be recreated.
  114. }
  115. /*
  116. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  117. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
  118. // Configure the cell...
  119. return cell;
  120. }
  121. */
  122. /*
  123. // Override to support conditional editing of the table view.
  124. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
  125. // Return NO if you do not want the specified item to be editable.
  126. return YES;
  127. }
  128. */
  129. /*
  130. // Override to support editing the table view.
  131. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  132. if (editingStyle == UITableViewCellEditingStyleDelete) {
  133. // Delete the row from the data source
  134. [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  135. } else if (editingStyle == UITableViewCellEditingStyleInsert) {
  136. // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
  137. }
  138. }
  139. */
  140. /*
  141. // Override to support rearranging the table view.
  142. - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
  143. }
  144. */
  145. /*
  146. // Override to support conditional rearranging of the table view.
  147. - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
  148. // Return NO if you do not want the item to be re-orderable.
  149. return YES;
  150. }
  151. */
  152. /*
  153. #pragma mark - Navigation
  154. // In a storyboard-based application, you will often want to do a little preparation before navigation
  155. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  156. // Get the new view controller using [segue destinationViewController].
  157. // Pass the selected object to the new view controller.
  158. }
  159. */
  160. @end