SYBase_tbVC.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. self.navigationController.navigationBar.translucent = NO;
  16. [self goBackByNavigation];
  17. _dataSource = [[NSMutableArray alloc]init];
  18. _sectionTitles = [[NSMutableArray alloc]init];
  19. _requsetDic = [[NSMutableDictionary alloc]init];
  20. _tableView = [[UITableView alloc]initWithFrame:kFrame];
  21. _tableView.height = kSize.height - kNavOffSet;
  22. _tableView.dataSource = self;
  23. _tableView.delegate = self;
  24. [self.view addSubview:_tableView];
  25. self.tableView.tableFooterView = [UIView new];
  26. [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cellId"];
  27. self.tableView.sectionIndexColor = defGreen;
  28. self.tableView.tableFooterView = [UIView new];
  29. self.holderV = [[HolderView alloc] initWithFrame:_tableView.frame];
  30. [self.holderV freshBlock:^{
  31. if (_holdervBlock) {
  32. _holdervBlock();
  33. }
  34. }];
  35. [self.view addSubview:self.holderV];
  36. }
  37. #pragma mark 获取数据
  38. -(void)getDataWithDic:(NSMutableDictionary *)mdic method:(NSString *)method block:(Block)block{
  39. //判断网络是否连接
  40. if (![NetManager connectedToNetWork]) {
  41. showMsgUnconnect();
  42. return;
  43. }
  44. [MBProgressHUD showLoadToView:self.view];
  45. [NetManager requestAnythingWithURL:method dictionary:mdic dataArray:nil completion:^(NSDictionary *root) {
  46. [MBProgressHUD hideHUDForView:self.view];
  47. [self.holderV setHidden:NO];
  48. if (!root) {
  49. ShowMsg(@"数据请求失败,请重试");
  50. return;
  51. }
  52. if ([root[@"code"] integerValue] == 1) {
  53. ShowMsg(root[@"msg"]);
  54. return;
  55. }
  56. if (block) {
  57. block(root);
  58. }
  59. }];
  60. }
  61. #pragma mark 弹出框提示
  62. - (void)showMsgByAlertVCWithString:(NSString *)str{
  63. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:str preferredStyle:UIAlertControllerStyleAlert];
  64. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];
  65. [self presentViewController:alertFind animated:true completion:nil];
  66. }
  67. #pragma mark 代理方法
  68. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  69. return _dataSource.count;
  70. }
  71. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  72. return [_dataSource[section] count];
  73. }
  74. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  75. {
  76. return nil;
  77. }
  78. // 每个分区的页眉
  79. -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
  80. {
  81. return [_sectionTitles objectAtIndex:section];
  82. }
  83. // 索引目录
  84. -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
  85. {
  86. return _sectionTitles;
  87. }
  88. // 点击目录(响应索引点击)
  89. -(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  90. {
  91. // 获取所点目录对应的indexPath值
  92. NSIndexPath *selectIndexPath = [NSIndexPath indexPathForRow:0 inSection:index];
  93. // 让table滚动到对应的indexPath位置
  94. [tableView scrollToRowAtIndexPath:selectIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
  95. return index;
  96. }
  97. - (void)didReceiveMemoryWarning {
  98. [super didReceiveMemoryWarning];
  99. // Dispose of any resources that can be recreated.
  100. }
  101. @end