IVTMeMiTangViewController.m
7.94 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
//
// IVTMeMiTangViewController.m
// IVTMeLive
//
// Created by XRG on 16/5/31.
// Copyright © 2016年 Joky. All rights reserved.
//
#import "IVTMeMiTangViewController.h"
#import "Masonry.h"
#import "UIColor+IVTMeColor.h"
#import "UIFont+IVTMeFont.h"
#import "IVTMeSupportFirstCell.h"
#import "IVTMeSupportCommonCell.h"
#import "IVTUserInfoCenterViewController.h"
@interface IVTMeMiTangViewController ()<UITableViewDataSource,UITableViewDelegate>
{
NSArray *imageArray;
NSMutableArray *requestDataArray;
UILabel * noDataLabel;
}
@property (nonatomic, retain) UITableView *hintTable;
@end
@implementation IVTMeMiTangViewController
- (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];
}
- (void)doChangeFollowStatus{
[_hintTable reloadData];
}
-(void)initNav{
//整体背景nav view
UIView* navBgView = [[UIView alloc] init];
[self.view addSubview:navBgView];
navBgView.backgroundColor = [UIColor IVTLightRedColor];
__unsafe_unretained typeof (self) wself = self;
[navBgView mas_makeConstraints:^(MASConstraintMaker* make) {
make.left.equalTo(wself.view.mas_left);
make.right.equalTo(wself.view.mas_right);
make.top.equalTo(@0);
make.height.equalTo(@58);
}];
UILabel *setting = [[UILabel alloc]init];
[navBgView addSubview:setting];
setting.text = @"蜜糖贡献榜";
setting.textColor = [UIColor YXColorWithHexCode:@"#FFFFFF"];
setting.font = [UIFont YXFontOfSize:19];
[setting mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(navBgView.mas_centerX);
make.top.equalTo(wself.view.mas_top).with.offset(29);
make.size.mas_equalTo(CGSizeMake(100.0f, 19.0f));
}];
//背景nav 返回上级页面按钮
UIButton* backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[navBgView addSubview:backButton];
UIImage* navImage = [UIImage imageNamed:@"返回键"];
[backButton mas_makeConstraints:^(MASConstraintMaker* make) {
make.left.equalTo(wself.view);
make.top.equalTo(wself.view.mas_top).with.offset(18);
make.size.mas_equalTo(CGSizeMake(40, 40));
}];
[backButton setImage:navImage forState:UIControlStateNormal];
backButton.imageEdgeInsets = UIEdgeInsetsMake(5,5,5,5);
[backButton addTarget:self action:@selector(backToTopPage:) forControlEvents:UIControlEventTouchUpInside];
}
//返回按钮点击
-(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, 58, 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