MitangViewController.m
6.2 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
//
// MitangViewController.m
// IVTMeLiveTwo
//
// Created by xrg on 16/10/14.
// Copyright © 2016年 QLQ. All rights reserved.
//
#import "MitangViewController.h"
@interface MitangViewController ()<UITableViewDataSource,UITableViewDelegate>
{
NSArray *imageArray;
NSMutableArray *requestDataArray;
UILabel * noDataLabel;
}
@property (nonatomic, retain) UITableView *hintTable;
@end
@implementation MitangViewController
- (void)viewDidLoad {
[super viewDidLoad];
requestDataArray = [[NSMutableArray alloc]initWithCapacity:10];
self.view.backgroundColor = [UIColor IVTBackgroundColor];
[self buildHintTable];
imageArray = @[@"贡献榜第一名",@"贡献榜第二名",@"贡献榜第三名"];
[self request];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doChangeFollowStatus) name:@"followedChanged" object:nil];
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];
self.navigationItem.title = @"蜜糖贡献榜";
}
- (void)doChangeFollowStatus{
[_hintTable reloadData];
}
//返回按钮点击
-(void)backToTopPage:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
- (void)buildHintTable
{
if (_hintTable==nil) {
self.hintTable = [[UITableView alloc] init];
_hintTable.backgroundColor = [UIColor IVTBackgroundColor];
_hintTable.frame = CGRectMake(0, 0, kScreenWidth , kScreenHeight-58);
_hintTable.delegate = self;
_hintTable.dataSource = self;
_hintTable.showsHorizontalScrollIndicator = NO;
_hintTable.showsVerticalScrollIndicator = NO;
_hintTable.separatorStyle = UITableViewCellSeparatorStyleNone;
_hintTable.tableFooterView = [UIView new];
[self.view addSubview:_hintTable];
}
}
#pragma Mark - 网络请求
-(void)request{
NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
if (_isMain==YES) {
[dict setObject:[IVTAccountTool getUserId] forKey:@"userId"];
}else{
[dict setObject:self.userID forKey:@"userId"];
}
[dict setObject:[IVTAccountTool getPassword] forKey:@"captcha"];
[dict setObject:[IVTAccountTool getUserName] forKey:@"username"];
[dict setObject:@"1" forKey:@"page"];
[[IVTNetworkAPIClient sharedClient] getContributionListForUser:dict success:^(NSDictionary *successData) {
[requestDataArray addObjectsFromArray:[successData valueForKey:@"data"]];
if (requestDataArray.count == 0) {
noDataLabel.hidden = NO;
}
else{
noDataLabel.hidden = YES;
if (requestDataArray!=nil) {
for (int i=0; i<[requestDataArray count]; i++) {
NSMutableDictionary *listDic =[[requestDataArray objectAtIndex:i] mutableCopy];
[listDic setObject:[NSString stringWithFormat:@"%ld",[listDic[@"userId"] integerValue]] forKey:@"id"];
[requestDataArray replaceObjectAtIndex:i withObject:[listDic copy]];
}
}
}
[_hintTable reloadData];
} error:^(NSDictionary *successData) {
} failure:^(NSError *failureError) {
LRLog(@"failureError:%@",failureError);
}];
}
#pragma mark - table datasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return requestDataArray.count;
}
- (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 addSubview:[self addLineViews]];
}
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 addSubview:[self addLineView]];
cell.selectionStyle =UITableViewCellSelectionStyleNone;
}
cell.entity = [requestDataArray objectAtIndex:indexPath.row];
return cell;
}
}
#pragma mark - table delegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row==0 || indexPath.row==2 || indexPath.row==1) {
return 77;
}else{
return 59;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
IVTUserInfoCenterViewController *userInfo = [[IVTUserInfoCenterViewController alloc]init];
userInfo.userId = [NSString stringWithFormat:@"%ld",[[requestDataArray[indexPath.row] valueForKey:@"userId"] integerValue]];
[self.navigationController pushViewController:userInfo animated:YES];
}
- (UIView*)addLineView
{
UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 59.0-0.5, kScreenWidth, 0.5)];
line.backgroundColor = [UIColor IVTSeparatorColor];
return line;
}
- (UIView*)addLineViews
{
UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 77.0-0.5, kScreenWidth, 0.5)];
line.backgroundColor = [UIColor IVTSeparatorColor];
return line;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end