developer
2023-11-10 fd94d7149c22bca6e323de3e44d28a50d7bbf481
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
//
//  Personal_informationViewController.m
//  BuWanVideo2.0
//
//  Created by apple on 16/10/12.
//  Copyright © 2016年 com.yeshi.buwansheque.ios. All rights reserved.
//
 
#import "Personal_informationViewController.h"
#import "IconTableViewCell.h"
#import "InfoTableViewCell.h"
#import "signatureTableViewCell.h"
 
@interface Personal_informationViewController ()<UITableViewDelegate,UITableViewDataSource,UINavigationControllerDelegate,UIImagePickerControllerDelegate>{
    UITableView *_tableView;
    NSMutableArray *_dataArr;
    
    BOOL _hasChanged; //是否含有修改
    UIImage *_newiconImage; //自己截取,并且还未上传的头像
    
    //以下属性是从网络获取的数据,如果为nil,说明没有数据,加载默认属性就可以了
    NSString *_portrait;//头像的URL
    NSString *_Nickname;//昵称
    NSString *_Sex;//性别
    NSString *_BirthDay;//出生日期
    NSString *_Sign;//个性签名
    
    //当用户修改用户名时,用于存储临时变量,为什么不直接在_Nickname上修改呐?--为的是防止用户点取消保存的按钮!!!
    NSString *_tempNickname;
    NSString *_tempSign;
    //装载时间选择器的视图
    UIView *_dateView;
    //装载时间选选择器背后的半透明背景
    UIView *datePickerView;
    //时间选择器
    UIDatePicker *datePicker;
}
 
@end
 
@implementation Personal_informationViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadData];
}
-(void)loadData{
    self.navigationItem.title = @"个人资料";
    self.navigationController.navigationBar.titleTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:[UIColor blackColor]};
    //返回按钮
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[[UIImage imageNamed:@"详情页面返回"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(0, 0, 32, 32);
    UIBarButtonItem *iconBarItem=[[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.leftBarButtonItem = iconBarItem;
    
    //保存按钮
    UIButton *saveButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [saveButton setTitle:@"保存" forState:UIControlStateNormal];
    [saveButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [saveButton setTitleColor:[UIColor grayColor] forState:UIControlStateSelected];
    [saveButton addTarget:self action:@selector(SaveInfo) forControlEvents:UIControlEventTouchUpInside];
    saveButton.frame=CGRectMake(0, 0, 44, 32);
    UIBarButtonItem *saveBarItem=[[UIBarButtonItem alloc] initWithCustomView:saveButton];
    self.navigationItem.rightBarButtonItem=saveBarItem;
    
    //列表
    _dataArr  = [[NSMutableArray alloc] initWithObjects:@[@"修改头像"],@[@"昵称",@"生日",@"性别"],@[@"个性签名"], nil];
    
    if(_tableView==nil){
        _tableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, KScreenH) style:UITableViewStyleGrouped];
        _tableView.delegate=self;
        _tableView.dataSource=self;
        [self.view addSubview:_tableView];
        _tableView.backgroundColor=kGlobalBackgroundColor;
    }
    [_tableView registerNib:[UINib nibWithNibName:@"IconTableViewCell" bundle:nil] forCellReuseIdentifier:@"IconTableViewCell"];
    [_tableView registerNib:[UINib nibWithNibName:@"InfoTableViewCell" bundle:nil] forCellReuseIdentifier:@"InfoTableViewCell"];
    [_tableView registerNib:[UINib nibWithNibName:@"signatureTableViewCell" bundle:nil] forCellReuseIdentifier:@"signatureTableViewCell"];
    
    //从网络获取数据
    [self getInfoFromInternet];
}
 
/**
 从网络获取数据
 */
-(void)getInfoFromInternet{
    [[YTHNetInterface startInterface] getLoginUserInfoWithUid:[YTHsharedManger startManger].Uid WithSystem:@"1" WithLoginUid:[[NSUserDefaults standardUserDefaults] objectForKey:@"LoginUid"] withBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if (isSuccessful) {
            //首先判断数据是否获成功
            NSString *err=[NSString stringWithFormat:@"%@",[result objectForKey:@"Error"]];
            if (err.length==0) {
                if ([[result objectForKey:@"Data"] objectForKey:@"Portrait"]!=nil) {
                    NSString *str=[[result objectForKey:@"Data"] objectForKey:@"Portrait"];
                    NSLog(@"%@",str);
                    if ([[str substringWithRange:NSMakeRange(0, 4)] isEqualToString:@"http"]) {
                        _portrait=str;
                    }else{
                        _portrait=[NSString stringWithFormat:@"%@%@",iconImageUrl,str];
                    }
                }
                if ([[result objectForKey:@"Data"] objectForKey:@"Nickname"]!=nil) {
                    _Nickname=[[result objectForKey:@"Data"] objectForKey:@"Nickname"];
                }
                if ([[result objectForKey:@"Data"] objectForKey:@"Sex"]!=nil) {
                    _Sex=[[result objectForKey:@"Data"] objectForKey:@"Sex"];
                }
                if ([[result objectForKey:@"Data"] objectForKey:@"Birthday"]!=nil) {
                    _BirthDay=[[result objectForKey:@"Data"] objectForKey:@"Birthday"];
                }
                if ([[result objectForKey:@"Data"] objectForKey:@"Sign"]!=nil) {
                    _Sign=[[result objectForKey:@"Data"] objectForKey:@"Sign"];
                }
                //刷新列表数据
                [_tableView reloadData];
            }else{
                NSLog(@"%@",err);
            }
        }else{
            //提示用户网络连接失败,并提供
            if ([error compare:@"似乎已断开与互联网的连接。"] == 0) {
                [self autoDisappearAlertTime:1 msg:@"网络不可用,请检查网络"];
            }
        }
    }];
}
 
 
/**
 上传更改的信息
 */
-(void)SaveInfo{
    //判断是否有修改,如果没有修改就没有必要上传信息了
    if(_hasChanged){
        //要判断用户是否修改了头像,如果用户没有修改头像,就不需要同步头像
        NSString *iconStr;
        if(_newiconImage!=nil){
            //头像编码
            iconStr=[self imageTransFormBase64:_newiconImage];
        }
        [SVProgressHUD showWithStatus:@"保存中..."];
        [[YTHNetInterface startInterface] getupdateLoginUserInfoWithUid:[YTHsharedManger startManger].Uid WithSystem:@"1" WithLoginUid:[[NSUserDefaults standardUserDefaults] objectForKey:@"LoginUid"] WithSex:_Sex WithBirthDay:_BirthDay WithPersonalSign:_Sign WithNickName:_Nickname WithPortrait:_newiconImage==nil?nil:iconStr withBlock:^(BOOL isSuccessful, id result, NSString *error) {
            if (isSuccessful) {
                //请求成功
                NSString *err=[NSString stringWithFormat:@"%@",[result objectForKey:@"Error"]];
                if (err.length==0) {
                    //重新存储新的昵称
                    [[NSUserDefaults standardUserDefaults] setObject:_Nickname forKey:@"QQUserName"];
                    [[YTHNetInterface startInterface] getLoginUserInfoWithUid:[YTHsharedManger startManger].Uid WithSystem:@"1" WithLoginUid:[[NSUserDefaults standardUserDefaults] objectForKey:@"LoginUid"] withBlock:^(BOOL isSuccessful, id result, NSString *error) {
                        if (isSuccessful) {
                            //首先判断数据是否获成功
                            NSString *err=[NSString stringWithFormat:@"%@",[result objectForKey:@"Error"]];
                            if (err.length==0) {
                                //上传成功
                                _hasChanged=NO;
                                //跟新个人信息到全局变量
                                if ([[result objectForKey:@"Data"] objectForKey:@"Portrait"]!=nil) {
                                    NSString *str=[[result objectForKey:@"Data"] objectForKey:@"Portrait"];
                                    if ([[str substringWithRange:NSMakeRange(0, 4)] isEqualToString:@"http"]) {
                                        _portrait=str;
                                    }else{
                                        _portrait=[NSString stringWithFormat:@"%@%@",iconImageUrl,str];
                                    }
                                    [[NSUserDefaults standardUserDefaults] setObject:_portrait forKey:@"iconURL"];
                                }
                                if ([[result objectForKey:@"Data"] objectForKey:@"Nickname"]!=nil) {
                                    [[NSUserDefaults standardUserDefaults] setObject:_Nickname forKey:@"QQUserName"];
                                }
                                //通知刷新视图
                                [[NSNotificationCenter defaultCenter] postNotificationName:@"RELOAD_DATA" object:nil];
                                //显示保存成功
                                [SVProgressHUD showSuccessWithStatus:@"保存成功!"];
                            }else{
                                //错误原因
                                [SVProgressHUD dismiss];
                                NSLog(@"%@",err);
                            }
                        }else{
                            //提示用户网络连接失败,并提供
                            [SVProgressHUD showErrorWithStatus:@"保存失败!"];
                        }
                    }];
                }else{
                    //上传失败
                    [SVProgressHUD dismiss];
                    NSLog(@"%@",err);
                }
            }else{
                [SVProgressHUD dismiss];
                //请求失败,网络问题
            }
        }];
    }
}
 
/**
 返回
 
 @param sender 返回按钮
 */
-(void)back:(id)sender{
    if (_hasChanged) {
        //当前信息有修改,但是并未保存
        UIAlertController *Alert=[UIAlertController alertControllerWithTitle:@"当前信息未保存" message:@"是否保存修改信息" preferredStyle:UIAlertControllerStyleAlert];
        //取消按钮
        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            //退出当前界面
            _hasChanged=NO;
            [self.navigationController popViewControllerAnimated:YES];
        }];
        [Alert addAction:cancel];
        //保存按钮
        UIAlertAction *certain = [UIAlertAction actionWithTitle:@"保存" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [self SaveInfo];
        }];
        [Alert addAction:certain];
        [self presentViewController:Alert animated:YES completion:nil];
    }else{
        [self.navigationController popViewControllerAnimated:YES];
    }
}
 
 
/**
 隐藏时间选择器视图
 
 @param sender 按钮
 */
-(void)HiddenDateView:(UIButton *)sender{
    [datePickerView removeFromSuperview];
    [_dateView removeFromSuperview];
}
 
 
/**
 保存设置的日期,并移除时间选择器视图
 
 @param sender 按钮
 */
-(void)SaveDateView:(UIButton *)sender{
    NSDateFormatter* df = [[NSDateFormatter alloc]init];
    [df setDateFormat:@"yyyy-MM-dd"];
    _BirthDay = [df stringFromDate:datePicker.date];
    _hasChanged=YES;
    [_tableView reloadData];
    [datePickerView removeFromSuperview];
    [_dateView removeFromSuperview];
}
 
 
 
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if(indexPath.section==0){//修改头像
        /**
         *  弹出提示框
         */
        //初始化提示框
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        [alert addAction:[UIAlertAction actionWithTitle:@"从相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            UIImagePickerController *PickerImage = [[UIImagePickerController alloc]init];
            //获取方式1:通过相册(呈现全部相册),UIImagePickerControllerSourceTypePhotoLibrary
            //获取方式2,通过相机,UIImagePickerControllerSourceTypeCamera
            //获取方法3,通过相册(呈现全部图片),UIImagePickerControllerSourceTypeSavedPhotosAlbum
            PickerImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            //允许编辑,即放大裁剪
            PickerImage.allowsEditing = YES;
            //自代理
            PickerImage.delegate = self;
            //页面跳转
            [self presentViewController:PickerImage animated:YES completion:nil];
        }]];
        
        [alert addAction:[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            UIImagePickerController *PickerImage = [[UIImagePickerController alloc]init];
            //获取方式:通过相机
            PickerImage.sourceType = UIImagePickerControllerSourceTypeCamera;
            PickerImage.allowsEditing = YES;
            PickerImage.delegate = self;
            [PickerImage.navigationController.navigationBar setBackgroundColor:kGlobalMainColor];
            [self presentViewController:PickerImage animated:YES completion:nil];
        }]];
        [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
        [self presentViewController:alert animated:YES completion:nil];
        
    }else if (indexPath.section==1){
        if (indexPath.row==0) {//昵称
            UIAlertController *modifyNicknameAlert=[UIAlertController alertControllerWithTitle:@"修改昵称" message:@"昵称需要大于2个字符!" preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                //这里面写取消修改昵称的操作
            }];
            [modifyNicknameAlert addAction:cancel];
            UIAlertAction *certain = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                if (_tempNickname.length>1) {
                    _Nickname=_tempNickname;
                    _hasChanged=YES;
                    [_tableView reloadData];
                }
            }];
            [modifyNicknameAlert addAction:certain];
            
            [modifyNicknameAlert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
                // 监听
                [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleTextFieldTextDidChangeNotification:) name:UITextFieldTextDidChangeNotification object:textField];
                // 定制键盘和输入框背景文字及clearButton
                textField.placeholder = [NSString stringWithFormat:@"%@",_Nickname];
                textField.clearButtonMode = UITextFieldViewModeWhileEditing;
                textField.autocorrectionType=UITextAutocorrectionTypeNo;
            }];
            [self presentViewController:modifyNicknameAlert animated:YES completion:nil];
        }else if(indexPath.row==1){//生日
            datePicker=[[UIDatePicker alloc] initWithFrame:CGRectMake(0, 44, KScreenW, 216)];
            datePicker.backgroundColor=[UIColor whiteColor];
            //配置语言
            NSLocale *locale=[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
            datePicker.locale=locale;
            //配置类型
            datePicker.datePickerMode=UIDatePickerModeDate;
            //配置时间范围
            NSDate *maxDate = [[NSDate alloc]initWithTimeIntervalSince1970:0];
            datePicker.maximumDate = maxDate;
            NSDate *minDate = [NSDate date];
            datePicker.maximumDate = minDate;
            //设置输出的格式
            NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
            [dateFormatter setDateFormat:@"yyyy-MM-dd"];
            //设置初始时间
            NSDate* inputDate;
            if(_BirthDay!=nil){
                inputDate = [dateFormatter dateFromString:_BirthDay];
            }else{
                inputDate = [dateFormatter dateFromString:@"1990-01-01"];
            }
            [datePicker setDate:inputDate animated:YES];
            
            
            //将时间选择器放在一个视图上
            _dateView=[[UIView alloc] initWithFrame:CGRectMake(0, KScreenH-260, KScreenW, 260)];
            _dateView.backgroundColor=KGlobalLightGreyColor_255;
            //时间选择器的取消按钮
            UIButton *DatePickerCancelBtn=[[UIButton alloc] initWithFrame:CGRectMake(13, 7, 52, 30)];
            [DatePickerCancelBtn setTitle:@"取消" forState:UIControlStateNormal];
            [DatePickerCancelBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [DatePickerCancelBtn addTarget:self action:@selector(HiddenDateView:) forControlEvents:UIControlEventTouchUpInside];
            //时间选择器的确认按钮
            UIButton *DatePickerSureBtn=[[UIButton alloc] initWithFrame:CGRectMake(KScreenW-65, 7, 52, 30)];
            [DatePickerSureBtn setTitle:@"确定" forState:UIControlStateNormal];
            [DatePickerSureBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [DatePickerSureBtn addTarget:self action:@selector(SaveDateView:) forControlEvents:UIControlEventTouchUpInside];
            //添加
            [_dateView addSubview:datePicker];
            [_dateView addSubview:DatePickerCancelBtn];
            [_dateView addSubview:DatePickerSureBtn];
            
            //添加一层半透明的背景
            datePickerView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, KScreenH)];
            datePickerView.backgroundColor=KGlobalLightGreyColor_153;
            [self.view addSubview:datePickerView];
            [self.view addSubview:_dateView];
        }else{//性别
            UIAlertController *modifySexnameAlert=[UIAlertController alertControllerWithTitle:@"请选择你的性别" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
            
            UIAlertAction *man=[UIAlertAction actionWithTitle:@"男" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                _Sex=@"1";
                _hasChanged=YES;
                [_tableView reloadData];
                [modifySexnameAlert dismissViewControllerAnimated:YES completion:nil];
            }];
            [modifySexnameAlert addAction:man];
            
            UIAlertAction *woman=[UIAlertAction actionWithTitle:@"女" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                _Sex=@"0";
                _hasChanged=YES;
                [_tableView reloadData];
                [modifySexnameAlert dismissViewControllerAnimated:YES completion:nil];
            }];
            [modifySexnameAlert addAction:woman];
            
            UIAlertAction *cancel=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                
            }];
            [modifySexnameAlert addAction:cancel];
            
            [self presentViewController:modifySexnameAlert animated:YES completion:^{
                
            }];
        }
    }else{//个性签名
        UIAlertController *modifySignAlert=[UIAlertController alertControllerWithTitle:@"修改个性签名" message:nil preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            //这里面写取消修改昵称的操作
        }];
        [modifySignAlert addAction:cancel];
        UIAlertAction *certain = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            if (_tempSign.length>0) {
                _Sign=_tempSign;
                _hasChanged=YES;
                [_tableView reloadData];
            }
        }];
        [modifySignAlert addAction:certain];
        
        [modifySignAlert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
            // 监听
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(SignTextFieldTextDidChangeNotification:) name:UITextFieldTextDidChangeNotification object:textField];
            // 定制键盘和输入框背景文字及clearButton
            if (_Sign!=nil) {
                textField.placeholder = [NSString stringWithFormat:@"%@",_Sign];
                textField.text=_Sign;
                textField.autocorrectionType=UITextAutocorrectionTypeNo;
            }else{
                textField.placeholder =@"写出你的个性吧!";
            }
            
            textField.clearButtonMode = UITextFieldViewModeWhileEditing;
        }];
        [self presentViewController:modifySignAlert animated:YES completion:nil];
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        return 65;
    }else if(indexPath.section==1){
        return 50;
    }else{
        return 60;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==0) {
        return 22;
    }else{
        return 11;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return [NSString stringWithFormat:@""];
}
 
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [_dataArr[section] count];
}
 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        IconTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"IconTableViewCell"];
        cell.cellTitle.text=_dataArr[indexPath.section][indexPath.row];
        if (_newiconImage!=nil) {
            [cell.iconImageView setImage:_newiconImage];
        }else if (_portrait!=nil) {
            [cell.iconImageView setYthImageWithURL:_portrait placeholderImage:[UIImage imageNamed:@"关注默认头像"]];
        }else{
            cell.iconImageView.image=[UIImage imageNamed:@"关注默认头像"];
        }
        cell.backgroundColor=[UIColor whiteColor];
        return cell;
    }else if(indexPath.section==1){
        InfoTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"InfoTableViewCell"];
        cell.cellTitle.text=_dataArr[indexPath.section][indexPath.row];
        if (indexPath.row==0) {
            if (_Nickname!=nil) {
                cell.cellInfo.text=_Nickname;
            }else{
                cell.cellInfo.text=@"布丸用户";
            }
        }else if (indexPath.row==1){
            if (_BirthDay!=nil) {
                cell.cellInfo.text=_BirthDay;
            }else{
                cell.cellInfo.text=@"1990-01-01";
            }
        }else{
            if (_Sex!=nil) {
                if ([_Sex isEqualToString:@"0"]) {
                    cell.cellInfo.text=@"女";
                }else if ([_Sex isEqualToString:@"1"]){
                    cell.cellInfo.text=@"男";
                }
            }else{
                cell.cellInfo.text=@"未知";
            }
        }
        cell.cellInfo.textColor= [UIColor blackColor];
        cell.backgroundColor=[UIColor whiteColor];
        return cell;
    }else{
        signatureTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"signatureTableViewCell"];
        cell.cellTitle.text=_dataArr[indexPath.section][indexPath.row];
        if (_Sign!=nil) {
            cell.cellInfo.text=_Sign;
        }
        cell.backgroundColor=[UIColor whiteColor];
        return cell;
    }
}
 
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [datePickerView removeFromSuperview];
    [_dateView removeFromSuperview];
}
 
#pragma mark -UIImagePickerControllerDelegate
//PickerImage完成后的代理方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
    //定义一个newPhoto,用来存放我们选择的图片。
    UIImage *newPhoto = [info objectForKey:@"UIImagePickerControllerEditedImage"];
    _newiconImage= newPhoto;
    [_tableView reloadData];
    _hasChanged=YES;
    [self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark 监听事件
//昵称的监听
- (void)handleTextFieldTextDidChangeNotification:(NSNotification *)notification{
    UITextField *textField = notification.object;
    _tempNickname = textField.text;
}
//个性签名的监听
- (void)SignTextFieldTextDidChangeNotification:(NSNotification *)notification{
    UITextField *textField = notification.object;
    _tempSign = textField.text;
}
 
#pragma mark 图片编码
- (NSString *) imageTransFormBase64: (UIImage *) image{
    NSData *imageData = nil;
    imageData = UIImageJPEGRepresentation(image, 0.5);
    return [NSString stringWithFormat:@"%@",
            [imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength]];
}
 
@end