SYBase_tbVC.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //
  2. // SYBase_tbVC.m
  3. // LNManager
  4. //
  5. // Created by EchoShacolee on 2017/4/7.
  6. // Copyright © 2017年 lee. All rights reserved.
  7. //
  8. #import "SYBase_tbVC.h"
  9. @interface SYBase_tbVC ()<UITableViewDataSource,UITableViewDelegate>
  10. @end
  11. @implementation SYBase_tbVC
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. self.view.backgroundColor = KBackGroundColor;
  15. _dataSource = [[NSMutableArray alloc]init];
  16. _sectionTitles = [[NSMutableArray alloc]init];
  17. _requsetDic = [[NSMutableDictionary alloc]init];
  18. [self myInit];
  19. }
  20. -(void)myInit{
  21. _tableView = [[UITableView alloc]initWithFrame:self.view.bounds];
  22. _tableView.dataSource = self;
  23. _tableView.delegate = self;
  24. [self.view addSubview:_tableView];
  25. self.tableView.tableFooterView = [UIView new];
  26. [self.tableView registerClass:[SelectCell class] forCellReuseIdentifier:@"cellId"];
  27. //设置索引条颜色
  28. // self.tableView.sectionIndexBackgroundColor = [UIColor clearColor];
  29. self.tableView.sectionIndexColor = COLOR_THEME;
  30. self.holderV = [[HolderView alloc] initWithFrame:_tableView.frame];
  31. [self.holderV freshBlock:^{
  32. if (_block) {
  33. _block();
  34. }
  35. }];
  36. [self.view addSubview:self.holderV];
  37. }
  38. #pragma mark 获取数据
  39. -(void)getDataWithDic:(NSMutableDictionary *)mdic method:(NSString *)method block:(Block)block{
  40. //判断网络是否连接
  41. if (![NetworkManager connectedToNetWork]) {
  42. [self showMsgByAlertVCWithString:@"网络连接异常"];
  43. return;
  44. }
  45. [MBProgressHUD hideHUDForView:self.view animated:NO];
  46. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  47. [NetworkManager requestWithMethod:method parameters:mdic type:0 handler:^(NSDictionary *successDic, NSString *failureStr) {
  48. [MBProgressHUD hideHUDForView:self.view animated:YES];
  49. [self.holderV setHidden:NO];
  50. if (failureStr) {
  51. [self showMsgByAlertVCWithString:failureStr];
  52. return;
  53. }
  54. if ([successDic[@"code"] isEqualToString:@"1"]) {
  55. [self showMsgByAlertVCWithString:successDic[@"msg"]];
  56. return;
  57. }
  58. if (block) {
  59. block(successDic);
  60. }
  61. }];
  62. }
  63. #pragma mark 弹出框提示
  64. - (void)showMsgByAlertVCWithString:(NSString *)str{
  65. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:str preferredStyle:UIAlertControllerStyleAlert];
  66. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];
  67. [self presentViewController:alertFind animated:true completion:nil];
  68. }
  69. - (void)showMsgByMBWithString:(NSString *)str{
  70. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  71. hud.mode = MBProgressHUDModeText;
  72. hud.label.text = str;
  73. hud.margin = HUD_MARGIN;
  74. hud.removeFromSuperViewOnHide = YES;
  75. [hud hideAnimated:YES afterDelay:2];
  76. }
  77. #pragma mark 代理方法
  78. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  79. return _dataSource.count;
  80. }
  81. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  82. return [_dataSource[section] count];
  83. }
  84. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  85. {
  86. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"unuse"];
  87. if (!cell) {
  88. cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"unuse"];
  89. }
  90. return cell;
  91. }
  92. // 每个分区的页眉
  93. -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
  94. {
  95. return [_sectionTitles objectAtIndex:section];
  96. }
  97. // 索引目录
  98. -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
  99. {
  100. return _sectionTitles;
  101. }
  102. // 点击目录(响应索引点击)
  103. -(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  104. {
  105. // 获取所点目录对应的indexPath值
  106. NSIndexPath *selectIndexPath = [NSIndexPath indexPathForRow:0 inSection:index];
  107. // 让table滚动到对应的indexPath位置
  108. [tableView scrollToRowAtIndexPath:selectIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
  109. return index;
  110. }
  111. - (void)didReceiveMemoryWarning {
  112. [super didReceiveMemoryWarning];
  113. // Dispose of any resources that can be recreated.
  114. }
  115. @end