Commit 04e044ce authored by admin's avatar admin

添加并列排名

parent 26faa242
...@@ -28,4 +28,6 @@ ...@@ -28,4 +28,6 @@
+ (instancetype)rankListModelWithDict:(NSDictionary *)dict; + (instancetype)rankListModelWithDict:(NSDictionary *)dict;
- (instancetype)initWithDict:(NSDictionary *)dict; - (instancetype)initWithDict:(NSDictionary *)dict;
@property (nonatomic, assign) int index;
@end @end
...@@ -21,5 +21,5 @@ ...@@ -21,5 +21,5 @@
@property (nonatomic, strong) UIButton *pushButton; @property (nonatomic, strong) UIButton *pushButton;
+ (instancetype)headViewWithTableView:(UITableView *)tableView section:(NSInteger)section; + (instancetype)headViewWithTableView:(UITableView *)tableView section:(NSInteger)section index:(int)index;
@end @end
...@@ -27,19 +27,19 @@ ...@@ -27,19 +27,19 @@
@end @end
@implementation RankListHeaderView @implementation RankListHeaderView
+ (instancetype)headViewWithTableView:(UITableView *)tableView section:(NSInteger)section + (instancetype)headViewWithTableView:(UITableView *)tableView section:(NSInteger)section index:(int)index
{ {
static NSString *headIdentifier = @"header"; static NSString *headIdentifier = @"header";
RankListHeaderView *headView = (RankListHeaderView *)[tableView dequeueReusableCellWithIdentifier:headIdentifier]; RankListHeaderView *headView = (RankListHeaderView *)[tableView dequeueReusableCellWithIdentifier:headIdentifier];
if (headView == nil) { if (headView == nil) {
headView = [[RankListHeaderView alloc] initWithReuseIdentifier:headIdentifier section:(NSInteger)section]; headView = [[RankListHeaderView alloc] initWithReuseIdentifier:headIdentifier section:(NSInteger)section index:index];
} }
return headView; return headView;
} }
- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier section:(NSInteger)section - (id)initWithReuseIdentifier:(NSString *)reuseIdentifier section:(NSInteger)section index:(int)index
{ {
if (self = [super initWithReuseIdentifier:reuseIdentifier]) { if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
...@@ -71,9 +71,8 @@ ...@@ -71,9 +71,8 @@
[self addSubview:scoreLabel]; [self addSubview:scoreLabel];
_scoreLabel = scoreLabel; _scoreLabel = scoreLabel;
if (section < 3) { if (index < 3) {
UIImageView *gradeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"medal_0%d", index]]];
UIImageView *gradeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"medal_0%d", (int)section + 1]]];
[self addSubview:gradeImageView]; [self addSubview:gradeImageView];
_gradeImageView = gradeImageView; _gradeImageView = gradeImageView;
...@@ -83,7 +82,7 @@ ...@@ -83,7 +82,7 @@
gradeLabel.textAlignment = NSTextAlignmentCenter; gradeLabel.textAlignment = NSTextAlignmentCenter;
[self addSubview:gradeLabel]; [self addSubview:gradeLabel];
NSString *rankStr = [NSString stringWithFormat:@"第 %d 名", (int)section + 1]; NSString *rankStr = [NSString stringWithFormat:@"第 %d 名", index];
NSMutableAttributedString *rankAttr = [[NSMutableAttributedString alloc] initWithString:rankStr]; NSMutableAttributedString *rankAttr = [[NSMutableAttributedString alloc] initWithString:rankStr];
[rankAttr addAttributes:@{NSForegroundColorAttributeName:kRankHeadTitleTextColor,NSFontAttributeName:[UIFont systemFontOfSize:14.0f]} range:NSMakeRange(0,1)]; [rankAttr addAttributes:@{NSForegroundColorAttributeName:kRankHeadTitleTextColor,NSFontAttributeName:[UIFont systemFontOfSize:14.0f]} range:NSMakeRange(0,1)];
[rankAttr addAttributes:@{NSForegroundColorAttributeName:kGradeNumberTextColor} range:NSMakeRange(1,rankStr.length - 2)]; [rankAttr addAttributes:@{NSForegroundColorAttributeName:kGradeNumberTextColor} range:NSMakeRange(1,rankStr.length - 2)];
......
...@@ -140,7 +140,15 @@ ...@@ -140,7 +140,15 @@
[tgArray addObject:rankList]; [tgArray addObject:rankList];
} }
_rankData = (NSMutableArray *)[self sortRankListWithRankListArray:tgArray]; _rankData = (NSMutableArray *)[self sortRankListWithRankListArray:tgArray];
for (int i = 0 ; i < _rankData.count; i++) {
RankListModel *rank = _rankData[i];
if (i == 0) {
rank.index = i + 1;
} else {
RankListModel *prevRank = _rankData[i-1];
rank.index = rank.score == prevRank.score ? prevRank.index: i + 1;
}
}
if (_rankData.count == 0) { if (_rankData.count == 0) {
weakSelf.noDataView.backgroundColor = [UIColor whiteColor]; weakSelf.noDataView.backgroundColor = [UIColor whiteColor];
[MBProgressHUD hideHUDForView:self.view animated:YES]; [MBProgressHUD hideHUDForView:self.view animated:YES];
...@@ -199,6 +207,17 @@ ...@@ -199,6 +207,17 @@
[tgArray addObject:rankList]; [tgArray addObject:rankList];
} }
_rankData = (NSMutableArray *)[self sortRankListWithRankListArray:tgArray]; _rankData = (NSMutableArray *)[self sortRankListWithRankListArray:tgArray];
for (int i = 0 ; i < _rankData.count; i++) {
RankListModel *rank = _rankData[i];
if (i == 0) {
rank.index = i + 1;
} else {
RankListModel *prevRank = _rankData[i-1];
rank.index = rank.score == prevRank.score ? prevRank.index: i + 1;
}
}
[self.tableView reloadData]; [self.tableView reloadData];
[MBProgressHUD hideHUDForView:self.view animated:YES]; [MBProgressHUD hideHUDForView:self.view animated:YES];
...@@ -416,11 +435,11 @@ ...@@ -416,11 +435,11 @@
if (section == 0) { if (section == 0) {
return nil; return nil;
} else { } else {
RankListModel *rankList = _rankData[section - 1];
RankListHeaderView *headView = [RankListHeaderView headViewWithTableView:tableView section:section - 1]; RankListHeaderView *headView = [RankListHeaderView headViewWithTableView:tableView section:section - 1 index:rankList.index];
headView.delegate = self; headView.delegate = self;
[headView.pushButton addTarget:self action:@selector(pushclick:) forControlEvents:UIControlEventTouchUpInside]; [headView.pushButton addTarget:self action:@selector(pushclick:) forControlEvents:UIControlEventTouchUpInside];
headView.rankListModel = _rankData[section - 1]; headView.rankListModel = rankList;
return headView; return headView;
} }
} }
...@@ -428,8 +447,7 @@ ...@@ -428,8 +447,7 @@
- (void)pushclick:(UIButton *)sender - (void)pushclick:(UIButton *)sender
{ {
NSInteger section = sender.tag - kPushTag; NSInteger section = sender.tag - kPushTag;
RankListModel *rankList = _rankData[section];
RankListModel *rankList = _rankData[section - 1];
RankDetailViewController *rankDetailVC = [[RankDetailViewController alloc] init]; RankDetailViewController *rankDetailVC = [[RankDetailViewController alloc] init];
rankDetailVC.indexRow = section - 1; rankDetailVC.indexRow = section - 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment