UserInfoViewController.m
9.03 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
//
// UserInfoViewController.m
// CNLiveUserSystemDemo
//
// Created by 朱林 on 16/9/17.
// Copyright © 2016年 zhulin. All rights reserved.
//
#import "UserInfoViewController.h"
#import "UserInfoHeaderImageTableViewCell.h"
#import "UserInfoTableViewCell.h"
#import "ModifyUserInfoViewController.h"
#import <AVFoundation/AVFoundation.h>
@interface UserInfoViewController ()<UITableViewDataSource, UITableViewDelegate, UIActionSheetDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIAlertViewDelegate,UIActionSheetDelegate>
{
UITableView *_tableView;
NSData *_imageData;
NSArray *_titlesArray;
NSArray *_detailsArray;
}
@end
@implementation UserInfoViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.title = @"个人资料";
_titlesArray = @[@"头像", @"更新手机号", @"昵称修改", @"性别修改", @"邮箱修改",@"地址修改"];
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight-64) style:UITableViewStylePlain];
[self.view addSubview:_tableView];
_tableView.showsHorizontalScrollIndicator = NO;
_tableView.showsVerticalScrollIndicator = NO;
_tableView.dataSource = self;
_tableView.delegate = self;
_tableView.backgroundColor = [UIColor clearColor];
_tableView.sectionHeaderHeight = 6;
_tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
}
#pragma mark - UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _titlesArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0 && indexPath.row == 0) {
return 63;
}
return 53;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0 && indexPath.row == 0) {
UserInfoHeaderImageTableViewCell *cell = [[UserInfoHeaderImageTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
return cell;
} else {
UserInfoTableViewCell *cell = [[UserInfoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
[cell setTitle:[_titlesArray objectAtIndex:indexPath.row] detail:(int)(indexPath.row+indexPath.section*5)];
return cell;
}
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 6)];
tableView.contentSize = CGSizeMake(KScreenWidth, 53*5+63+12+80+60);
return view;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
switch (indexPath.row) {
case 0:
{
UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"拍照" otherButtonTitles:@"从相册选择", nil];
action.tag = 100;
[action showInView:self.view];
}
break;
case 1:
{
ModifyUserInfoViewController *modify = [[ModifyUserInfoViewController alloc] init];
modify.title = @"更新手机号";
[self.navigationController pushViewController:modify animated:YES];
}
break;
case 2:
{
ModifyUserInfoViewController *modify = [[ModifyUserInfoViewController alloc] init];
modify.modifyType = UserInfoTypeNickName;
modify.title = @"昵称修改";
[self.navigationController pushViewController:modify animated:YES];
}
break;
case 3:
{
UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"男" otherButtonTitles:@"女", nil];
action.tag = 102;
[action showInView:self.view];
}
break;
case 4:
{
ModifyUserInfoViewController *modify = [[ModifyUserInfoViewController alloc] init];
modify.title = @"邮箱修改";
modify.modifyType = UserInfoTypeEmail;
[self.navigationController pushViewController:modify animated:YES];
}
break;
case 5:
{
ModifyUserInfoViewController *modify = [[ModifyUserInfoViewController alloc] init];
modify.title = @"联系方式修改";
modify.modifyType = UserInfoTypeLocation;
[self.navigationController pushViewController:modify animated:YES];
}
break;
}
}
#pragma mark - UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (actionSheet.tag == 102) {
if (buttonIndex == 0) {
[self modifyGender:@"m"];
} else if (buttonIndex == 1) {
[self modifyGender:@"f"];
}
}else if (actionSheet.tag == 100) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
switch (buttonIndex)
{
case 0:
{
if ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] == AVAuthorizationStatusDenied || [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] == AVAuthorizationStatusRestricted) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您未允许‘互动电视’访问您的相机,请在‘设置-隐私-相机’中更改设置" delegate:self cancelButtonTitle:nil otherButtonTitles:@"取消",@"去设置", nil];
alert.tag = 1001;
[alert show];
return;
}
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:imagePicker animated:YES completion:NULL];
} else {
[Tools toast:@"您的设备没有相机功能!"];
}
}
break;
case 1:
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imagePicker animated:YES completion:NULL];
break;
}
}
}
- (void)modifyGender:(NSString *)string
{
[SVProgressHUD show];
UserInfoModel *model = [UserInfoModel modelWithKeyValues:[Tools getLocalUserInfo]];
[CNLiveUserSystemCenter modifyUserInfoType:UserInfoTypeGender uid:model.uid modifyInfo:string success:^(id result) {
NSLog(@"%@",result);
if ([[result allKeys] containsObject:@"errorCode"] && [result[@"errorCode"] isEqualToString:@"0"]) {
[SVProgressHUD showSuccessWithStatus:@"修改成功"];
} else {
[Tools toast:result[@"errorMessage"]];
[SVProgressHUD dismiss];
}
} failure:^(NSError *error) {
[Tools toast:error.localizedDescription];
[SVProgressHUD dismiss];
}];
}
#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:NULL];
UIImage* image = [info objectForKey:UIImagePickerControllerEditedImage];
if ([image isKindOfClass:[UIImage class]]) {
[self postPhoto:image];
} else {
[Tools toast:@"获取图片失败"];
}
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:NULL];
}
-(void)postPhoto:(UIImage *)image
{
if (image) {
UserInfoModel *model = [UserInfoModel modelWithKeyValues:[Tools getLocalUserInfo]];
[CNLiveUserSystemCenter uploadIconWithUid:model.uid icon:image success:^(id result) {
NSLog(@"%@",result);
} failure:^(NSError *error) {
[Tools toast:error.localizedDescription];
}];
} else {
[Tools toast:@"获取图片失败"];
}
}
- (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