Commit 04e044ce authored by admin's avatar admin

添加并列排名

parent 26faa242
No preview for this file type
......@@ -28,4 +28,6 @@
+ (instancetype)rankListModelWithDict:(NSDictionary *)dict;
- (instancetype)initWithDict:(NSDictionary *)dict;
@property (nonatomic, assign) int index;
@end
......@@ -21,5 +21,5 @@
@property (nonatomic, strong) UIButton *pushButton;
+ (instancetype)headViewWithTableView:(UITableView *)tableView section:(NSInteger)section;
+ (instancetype)headViewWithTableView:(UITableView *)tableView section:(NSInteger)section index:(int)index;
@end
......@@ -27,19 +27,19 @@
@end
@implementation RankListHeaderView
+ (instancetype)headViewWithTableView:(UITableView *)tableView section:(NSInteger)section
+ (instancetype)headViewWithTableView:(UITableView *)tableView section:(NSInteger)section index:(int)index
{
static NSString *headIdentifier = @"header";
RankListHeaderView *headView = (RankListHeaderView *)[tableView dequeueReusableCellWithIdentifier:headIdentifier];
if (headView == nil) {
headView = [[RankListHeaderView alloc] initWithReuseIdentifier:headIdentifier section:(NSInteger)section];
headView = [[RankListHeaderView alloc] initWithReuseIdentifier:headIdentifier section:(NSInteger)section index:index];
}
return headView;
}
- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier section:(NSInteger)section
- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier section:(NSInteger)section index:(int)index
{
if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
......@@ -71,9 +71,8 @@
[self addSubview:scoreLabel];
_scoreLabel = scoreLabel;
if (section < 3) {
UIImageView *gradeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"medal_0%d", (int)section + 1]]];
if (index < 3) {
UIImageView *gradeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"medal_0%d", index]]];
[self addSubview:gradeImageView];
_gradeImageView = gradeImageView;
......@@ -83,7 +82,7 @@
gradeLabel.textAlignment = NSTextAlignmentCenter;
[self addSubview:gradeLabel];
NSString *rankStr = [NSString stringWithFormat:@"第 %d 名", (int)section + 1];
NSString *rankStr = [NSString stringWithFormat:@"第 %d 名", index];
NSMutableAttributedString *rankAttr = [[NSMutableAttributedString alloc] initWithString:rankStr];
[rankAttr addAttributes:@{NSForegroundColorAttributeName:kRankHeadTitleTextColor,NSFontAttributeName:[UIFont systemFontOfSize:14.0f]} range:NSMakeRange(0,1)];
[rankAttr addAttributes:@{NSForegroundColorAttributeName:kGradeNumberTextColor} range:NSMakeRange(1,rankStr.length - 2)];
......
......@@ -140,7 +140,15 @@
[tgArray addObject:rankList];
}
_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) {
weakSelf.noDataView.backgroundColor = [UIColor whiteColor];
[MBProgressHUD hideHUDForView:self.view animated:YES];
......@@ -199,6 +207,17 @@
[tgArray addObject:rankList];
}
_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];
[MBProgressHUD hideHUDForView:self.view animated:YES];
......@@ -416,11 +435,11 @@
if (section == 0) {
return nil;
} else {
RankListHeaderView *headView = [RankListHeaderView headViewWithTableView:tableView section:section - 1];
RankListModel *rankList = _rankData[section - 1];
RankListHeaderView *headView = [RankListHeaderView headViewWithTableView:tableView section:section - 1 index:rankList.index];
headView.delegate = self;
[headView.pushButton addTarget:self action:@selector(pushclick:) forControlEvents:UIControlEventTouchUpInside];
headView.rankListModel = _rankData[section - 1];
headView.rankListModel = rankList;
return headView;
}
}
......@@ -428,8 +447,7 @@
- (void)pushclick:(UIButton *)sender
{
NSInteger section = sender.tag - kPushTag;
RankListModel *rankList = _rankData[section - 1];
RankListModel *rankList = _rankData[section];
RankDetailViewController *rankDetailVC = [[RankDetailViewController alloc] init];
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