SYBase_tbVC.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 = RQMianColor;
  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. [NetManager requestAnythingWithURL:method dictionary:mdic dataArray:nil completion:^(NSDictionary *root) {
  45. [self.holderV setHidden:NO];
  46. if (!root) {
  47. ShowMsg(@"数据请求失败,请重试");
  48. return;
  49. }
  50. if ([root[@"code"] integerValue] == 1) {
  51. ShowMsg(root[@"msg"]);
  52. return;
  53. }
  54. if (block) {
  55. block(root);
  56. }
  57. }];
  58. }
  59. #pragma mark 弹出框提示
  60. - (void)showMsgByAlertVCWithString:(NSString *)str{
  61. [RQ_SHARE_FUNCTION showAlertWithTitle:nil message:str alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil completion:nil];
  62. }
  63. #pragma mark 代理方法
  64. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  65. return _dataSource.count;
  66. }
  67. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  68. return [_dataSource[section] count];
  69. }
  70. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  71. {
  72. return nil;
  73. }
  74. // 每个分区的页眉
  75. -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
  76. {
  77. return [_sectionTitles objectAtIndex:section];
  78. }
  79. // 索引目录
  80. -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
  81. {
  82. return _sectionTitles;
  83. }
  84. // 点击目录(响应索引点击)
  85. -(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  86. {
  87. // 获取所点目录对应的indexPath值
  88. NSIndexPath *selectIndexPath = [NSIndexPath indexPathForRow:0 inSection:index];
  89. // 让table滚动到对应的indexPath位置
  90. [tableView scrollToRowAtIndexPath:selectIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
  91. return index;
  92. }
  93. - (void)didReceiveMemoryWarning {
  94. [super didReceiveMemoryWarning];
  95. // Dispose of any resources that can be recreated.
  96. }
  97. @end