ViewController.m
7.49 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
//
// ViewController.m
// CNLiveUserSystemDemo
//
// Created by iOS on 16/9/12.
// Copyright © 2016年 zhulin. All rights reserved.
//
#import "ViewController.h"
#import "LoginViewController.h"
#import "RegisterViewController.h"
#import "UserInfoViewController.h"
#import "CNLiveLogout.h"
#import "UserInfoSava.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
{
NSArray *_dataArr;
}
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIButton *loginBtn;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"用户云";
self.view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.tableView];
[self.tableView addSubview:self.loginBtn];
_dataArr = @[@"通过手机号修改密码",@"更新附加信息",@"修改用户信息",@"查询用户信息",@"反馈"];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if ([Tools isLogin]) {
[_loginBtn setTitle:@"注销" forState:UIControlStateNormal];
} else {
[_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
}
[_tableView reloadData];
}
#pragma mark - action
- (void)logoutBtnAction
{
if ([Tools isLogin]) {
[CNLiveLogout clearLocalUserInfo];
[Tools setUserLogin:NO];
[_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
[_tableView reloadData];
} else {
LoginViewController *loginVC = [[LoginViewController alloc] init];
[self.navigationController pushViewController:loginVC animated:YES];
}
}
#pragma mark - UITableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([Tools isLogin]) {
return _dataArr.count+1;
} else {
return 1;
}
return _dataArr.count+1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0) {
UITableViewCell *loginCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellID"];
UIImageView *iconImg = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 80, 80)];
iconImg.backgroundColor = [UIColor orangeColor];
[loginCell.contentView addSubview:iconImg];
UserInfoModel *model = [UserInfoModel modelWithKeyValues:[Tools getLocalUserInfo]];
[iconImg sd_setImageWithURL:[NSURL URLWithString:model.faceUrl] placeholderImage:[UIImage imageNamed:@""]];
UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(120, 0, KScreenWidth- 160, 120)];
if ([Tools isLogin]) {
name.text = @"已登录";
} else {
name.text = @"登录";
}
[loginCell.contentView addSubview:name];
return loginCell;
} else {
static NSString *cellIndentify = @"cellIndentify";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentify];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentify];
}
cell.textLabel.text = [NSString stringWithFormat:@"%@",_dataArr[indexPath.row-1]];
return cell;
}
return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.row == 1) {
RegisterViewController *regVC = [[RegisterViewController alloc] init];
regVC.type = @"forgetPwd";
[self.navigationController pushViewController:regVC animated:YES];
}
if (indexPath.row == 2) {
[SVProgressHUD show];
UserInfoModel *model = [UserInfoModel modelWithKeyValues:[Tools getLocalUserInfo]];
[CNLiveUserSystemCenter updateOtherInfoWithUid:model.uid extInfo:@"将要更新的附加信息,NSString类型" success:^(id result) {
NSLog(@"--------%@",result);
[SVProgressHUD showSuccessWithStatus:@"更新附加信息成功"];
[self.navigationController popViewControllerAnimated:YES];
} failure:^(NSDictionary *errorDic) {
[Tools toast:[NSString stringWithFormat:@"errorCode : %@ \n errorMessage : %@", errorDic[@"errorCode"],errorDic[@"errorMessage"]]];
[SVProgressHUD dismiss];
}];
}
if (indexPath.row == 3) {
UserInfoViewController *userInfo = [[UserInfoViewController alloc] init];
[self.navigationController pushViewController:userInfo animated:YES];
}
if (indexPath.row == 4) {
UserInfoModel *model = [UserInfoModel modelWithKeyValues:[Tools getLocalUserInfo]];
[CNLiveUserSystemCenter queryUserInfoWithUid:model.uid srcUid:model.uid success:^(id result) {
NSLog(@"%@",result);
NSDictionary *dic = result[@"data"];
NSString *message = [NSString stringWithFormat:@" uid:%@\n nickName:%@\n gender:%@\n location:%@\n extInfo:%@\n mobile:%@\n email:%@",dic[@"uid"],dic[@"nickName"],dic[@"gender"],dic[@"location"],dic[@"extInfo"],dic[@"mobile"],dic[@"email"]];
NSString *icon = dic[@"faceUrl"];
[UserInfoSava setLocalUserInfo:icon withKey:@"faceUrl"];
[_tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
[Tools toast:message];
} failure:^(NSDictionary *errorDic) {
[Tools toast:[NSString stringWithFormat:@"errorCode : %@ \n errorMessage : %@", errorDic[@"errorCode"],errorDic[@"errorMessage"]]];
}];
}
if (indexPath.row == 5) {
[CNLiveUserSystemCenter feedbackWithContentId:@"11" message:@"fhsjhifkncznshfu" success:^(id result) {
[Tools toast:[NSString stringWithFormat:@"反馈--%@",result[@"errorMessage"]]];
} failure:^(NSDictionary *errorDic) {
[Tools toast:[NSString stringWithFormat:@"errorCode : %@ \n errorMessage : %@", errorDic[@"errorCode"],errorDic[@"errorMessage"]]];
}];
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0) {
return 120;
} else {
return 50;
}
}
#pragma mark - getter
- (UITableView *)tableView
{
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight) style:UITableViewStylePlain];
_tableView.backgroundColor = [UIColor whiteColor];
_tableView.tableFooterView = [[UIView alloc] init];
_tableView.delegate = self;
_tableView.dataSource = self;
}
return _tableView;
}
- (UIButton *)loginBtn
{
if (!_loginBtn) {
_loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_loginBtn.frame = CGRectMake(20, 53*5+63+12+80, KScreenWidth-40, 40);
[_loginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[_loginBtn setBackgroundColor:[UIColor orangeColor]];
_loginBtn.titleLabel.font = [UIFont systemFontOfSize:17];
[_loginBtn addTarget:self action:@selector(logoutBtnAction) forControlEvents:UIControlEventTouchUpInside];
_loginBtn.layer.cornerRadius = 20;
_loginBtn.layer.masksToBounds = YES;
}
return _loginBtn;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end