IVTMyContributionListViewController.m
6.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
//
// IVTMyContributionListViewController.m
// IVTMeLiveTwo
//
// Created by XRG on 16/8/23.
// Copyright © 2016年 QLQ. All rights reserved.
//
#import "IVTMyContributionListViewController.h"
#import "IVTMeSupportFirstCell.h"
#import "IVTMeSupportCommonCell.h"
#import "IVTUserInfoCenterViewController.h"
@interface IVTMyContributionListViewController ()<UITableViewDataSource,UITableViewDelegate>
{
NSArray *imageArray;
NSMutableArray *requestDataArray;
UITableView *myTableView;
UILabel *noDataLabel;
}
@end
@implementation IVTMyContributionListViewController
- (void)viewDidLoad {
[super viewDidLoad];
__weak __typeof(self)weakSelf = self;
[self setNavigationBar];
imageArray = @[@"贡献榜第一名",@"贡献榜第二名",@"贡献榜第三名"];
requestDataArray = [[NSMutableArray alloc]initWithCapacity:10];
noDataLabel = [[UILabel alloc]init];
noDataLabel.font = [UIFont systemFontOfSize:13];
noDataLabel.frame = CGRectMake(kScreenWidth / 2 - 100, kScreenWidth / 2 + 50, 200, 100);
noDataLabel.text = @"没有数据";
noDataLabel.hidden = YES;
noDataLabel.font = [UIFont systemFontOfSize:16];
noDataLabel.text = @"空空如也~~";
noDataLabel.textAlignment = 1;
[self.view addSubview:noDataLabel];
myTableView = [[UITableView alloc]init];
myTableView.delegate = self;
myTableView.dataSource = self;
myTableView.showsVerticalScrollIndicator = NO;
myTableView.showsHorizontalScrollIndicator = NO;
myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview:myTableView];
[myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(weakSelf.view.mas_left);
make.right.equalTo(weakSelf.view.mas_right);
make.top.equalTo(weakSelf.view.mas_top);
make.bottom.equalTo(weakSelf.view.mas_bottom);
}];
[self doRequest];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doChangeFollowStatus) name:@"followedChanged" object:nil];
}
- (void)setNavigationBar{
self.navigationItem.title = @"蜜糖贡献榜";
}
- (void)doChangeFollowStatus{
[myTableView reloadData];
}
- (void)doRequest{
[HUDUtil showLoading];
NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
[dict setObject:self.userId forKey:@"userId"];
[dict setObject:[IVTAccountTool getPassword] forKey:@"captcha"];
[dict setObject:[IVTAccountTool getUserName] forKey:@"username"];
[[IVTNetworkAPIClient sharedClient] getContributionListForUser:dict success:^(NSDictionary *successData) {
[HUDUtil hide];
NSMutableArray *dataArray = [[successData valueForKey:@"data"] mutableCopy];
if (requestDataArray!=nil) {
for (int i=0; i<[dataArray count]; i++) {
NSMutableDictionary *listDic =[[dataArray objectAtIndex:i] mutableCopy];
[listDic setObject:[NSString stringWithFormat:@"%ld",[listDic[@"userId"] integerValue]] forKey:@"id"];
[dataArray replaceObjectAtIndex:i withObject:[listDic copy]];
}
[requestDataArray addObjectsFromArray:dataArray];
if (requestDataArray.count > 0) {
noDataLabel.hidden = NO;
}
else{
noDataLabel.hidden = YES;
}
}
[myTableView reloadData];
} error:^(NSDictionary *successData) {
NSString *msg = successData[@"description"];
[HUDUtil showError:msg];
} failure:^(NSError *failureError) {
[HUDUtil showError:@"网络异常"];
}];
}
#pragma --mark UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return requestDataArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row==0 || indexPath.row==2 || indexPath.row==1) {
return 77;
}else{
return 59;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row==0 || indexPath.row==1 || indexPath.row==2) {
IVTMeSupportFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:@"supportFirstCell"];
if (!cell) {
cell = [[IVTMeSupportFirstCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"supportFirstCell"];
cell.backgroundColor =[UIColor IVTTitleColor];
cell.selectionStyle =UITableViewCellSelectionStyleNone;
}
cell.entity = [requestDataArray objectAtIndex:indexPath.row];
cell.goldImageName = imageArray[indexPath.row];
return cell;
}
else{
IVTMeSupportCommonCell *cell = [tableView dequeueReusableCellWithIdentifier:@"supportCell"];
if (!cell) {
cell = [[IVTMeSupportCommonCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"supportCell"];
cell.backgroundColor =[UIColor IVTTitleColor];
cell.selectionStyle =UITableViewCellSelectionStyleNone;
}
cell.entity = [requestDataArray objectAtIndex:indexPath.row];
return cell;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
IVTUserInfoCenterViewController *userInfoCenterVC = [[IVTUserInfoCenterViewController alloc]init];
userInfoCenterVC.userId = [NSString stringWithFormat:@"%ld",[[[requestDataArray objectAtIndex:indexPath.row] valueForKey:@"id"] integerValue]];
[self.navigationController pushViewController:userInfoCenterVC animated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end