ScoreRankVC.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. //
  2. // ScoreRankVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 15/11/28.
  6. // Copyright (c) 2015年 JCZ. All rights reserved.
  7. //
  8. #import "ScoreRankVC.h"
  9. #import "RankCell.h"
  10. #import "HolderView.h"
  11. @interface ScoreRankVC ()<UITableViewDataSource,UITableViewDelegate>
  12. {
  13. UITableView *myTableView;
  14. HolderView *holderV;
  15. //如果关闭功能 需要将这个去掉
  16. NSMutableArray *models;
  17. BOOL isRequest;
  18. }
  19. @end
  20. @implementation ScoreRankVC
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. [self myInit];
  24. }
  25. - (void)didReceiveMemoryWarning {
  26. [super didReceiveMemoryWarning];
  27. // Dispose of any resources that can be recreated.
  28. }
  29. #pragma mark -
  30. -(void)myInit
  31. {
  32. [self.view setBackgroundColor:[UIColor whiteColor]];
  33. [self configNavigationBar];
  34. [self setTitle:[NSString stringWithFormat:@"科目%@学霸排行榜",myDelegate.subject.intValue >1 ?@"四":@"一"]];
  35. models = [NSMutableArray array];
  36. myTableView = [[UITableView alloc] initWithFrame:kFrame];
  37. myTableView.height -= kNavOffSet;
  38. [myTableView setDelegate:self];
  39. [myTableView setDataSource:self];
  40. myTableView.tableFooterView = [UIView new];
  41. [self.view addSubview:myTableView];
  42. holderV = [[HolderView alloc] initWithFrame:myTableView.frame];
  43. [holderV freshBlock:^{
  44. if (!isRequest) {
  45. [self getScore];
  46. }
  47. }];
  48. [self.view addSubview:holderV];
  49. [self getScore];
  50. }
  51. #pragma mark -
  52. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  53. {
  54. return models.count;
  55. }
  56. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  57. {
  58. RankCell* cell = [tableView dequeueReusableCellWithIdentifier:@"scoreCell"];
  59. NSDictionary* dict = models[indexPath.row];
  60. if (!cell) {
  61. cell = [[RankCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"scoreCell"];
  62. [cell setUserInteractionEnabled:NO];
  63. }
  64. [cell setModel:dict];
  65. [cell setIndex:indexPath.row];
  66. switch (indexPath.row) {
  67. case 0:
  68. [cell setBackgroundColor:RGB_COLOR(254, 236, 235)];
  69. break;
  70. case 1:
  71. [cell setBackgroundColor:RGB_COLOR(254, 247, 232)];
  72. break;
  73. case 2:
  74. [cell setBackgroundColor:RGB_COLOR(239, 251, 232)];
  75. break;
  76. default:
  77. [cell setBackgroundColor:[UIColor clearColor]];
  78. break;
  79. }
  80. return cell;
  81. }
  82. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  83. {
  84. return [RankCell cellHeight];
  85. }
  86. //-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
  87. //{
  88. // //查看更多
  89. // CGPoint off = scrollView.contentOffset;
  90. // if (scrollView.contentSize.height - off.y - scrollView.frame.size.height < 1) {
  91. // [scrollView setContentOffset:CGPointMake(off.x, off.y - 10) animated:YES];
  92. // if (!isRequest) {
  93. // [self getScore];
  94. // }
  95. // }
  96. //}
  97. -(void)getScore
  98. {
  99. if (![Util connectedToNetWork]) {
  100. showMsgUnconnect();
  101. return;
  102. }
  103. isRequest = YES;
  104. NSMutableArray *arr=[NSMutableArray array];
  105. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:myDelegate.subject,@"subject", nil]];
  106. NSString* method = @"scoreRank";
  107. [MBProgressHUD showLoadToView:self.view];
  108. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  109. [MBProgressHUD hideHUDForView:self.view];
  110. holderV.hidden = NO;
  111. isRequest = NO;
  112. //NSLog(@"body------><>-%@--%@",arr,root[@"body"]);
  113. if (!root) {
  114. ShowMsgFailed();
  115. return;
  116. }
  117. if ([root[@"code"] isEqualToString:@"1"]) {
  118. ShowMsg(root[@"body"]);
  119. return;
  120. }
  121. if ([root[@"body"] isKindOfClass:[NSArray class]]) {
  122. if ([root[@"body"] count] < 1) {
  123. ShowMsg(@"已加载全部");
  124. return;
  125. }
  126. }else{
  127. NSLog(@"排行榜---%@",root[@"body"]);
  128. return;
  129. }
  130. models = [NSMutableArray arrayWithArray:root[@"body"]];
  131. if ([models count] > 0) {
  132. holderV.hidden = YES;
  133. }
  134. [myTableView reloadData];
  135. }];
  136. }
  137. @end