Base_tbVC.m 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. _IS_LOADING=NO;
  71. if (failureStr) {
  72. [self showMsgByAlertVCWithString:failureStr];
  73. return;
  74. }
  75. if ([successDic[@"code"] isEqualToString:@"1"]) {
  76. [self showMsgByAlertVCWithString:successDic[@"msg"]];
  77. return;
  78. }
  79. if (block) {
  80. block(successDic);
  81. }
  82. }];
  83. }
  84. #pragma mark 弹出框提示
  85. - (void)showMsgByAlertVCWithString:(NSString *)str{
  86. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:str preferredStyle:UIAlertControllerStyleAlert];
  87. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];
  88. [self presentViewController:alertFind animated:true completion:nil];
  89. }
  90. - (void)showMsgByMBWithString:(NSString *)str{
  91. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  92. hud.mode = MBProgressHUDModeText;
  93. hud.label.text = str;
  94. hud.margin = HUD_MARGIN;
  95. hud.removeFromSuperViewOnHide = YES;
  96. [hud hideAnimated:YES afterDelay:2];
  97. }
  98. #pragma mark 代理方法,具体实现子类完成
  99. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  100. return 0;
  101. }
  102. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  103. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"nouse"];
  104. return cell;
  105. }
  106. - (void)didReceiveMemoryWarning {
  107. [super didReceiveMemoryWarning];
  108. // Dispose of any resources that can be recreated.
  109. }
  110. /*
  111. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  112. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
  113. // Configure the cell...
  114. return cell;
  115. }
  116. */
  117. /*
  118. // Override to support conditional editing of the table view.
  119. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
  120. // Return NO if you do not want the specified item to be editable.
  121. return YES;
  122. }
  123. */
  124. /*
  125. // Override to support editing the table view.
  126. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  127. if (editingStyle == UITableViewCellEditingStyleDelete) {
  128. // Delete the row from the data source
  129. [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  130. } else if (editingStyle == UITableViewCellEditingStyleInsert) {
  131. // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
  132. }
  133. }
  134. */
  135. /*
  136. // Override to support rearranging the table view.
  137. - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
  138. }
  139. */
  140. /*
  141. // Override to support conditional rearranging of the table view.
  142. - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
  143. // Return NO if you do not want the item to be re-orderable.
  144. return YES;
  145. }
  146. */
  147. /*
  148. #pragma mark - Navigation
  149. // In a storyboard-based application, you will often want to do a little preparation before navigation
  150. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  151. // Get the new view controller using [segue destinationViewController].
  152. // Pass the selected object to the new view controller.
  153. }
  154. */
  155. @end