IVTEditMyNickNameViewController.m
3.56 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
//
// IVTEditMyNickNameViewController.m
// IVTMeLiveTwo
//
// Created by XRG on 16/8/24.
// Copyright © 2016年 QLQ. All rights reserved.
//
#import "IVTEditMyNickNameViewController.h"
@interface IVTEditMyNickNameViewController ()
{
UITextField *signTextField;
NSString *textString;
}
@end
@implementation IVTEditMyNickNameViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setNavigationBar];
UIView *backGround = [[UIView alloc]initWithFrame:CGRectMake(0, 5, kScreenWidth, 46)];
backGround.backgroundColor = [UIColor whiteColor];
[self.view addSubview:backGround];
signTextField = [[UITextField alloc]initWithFrame:CGRectMake(10, 0, kScreenWidth - 20, 46)];
signTextField.backgroundColor = [UIColor whiteColor];
signTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
signTextField.font = [UIFont IVTH3Font];
signTextField.textColor = [UIColor IVTMainTextColor];
signTextField.text = [[IVTAccountTool getNickName] base64DecodedToString];
[backGround addSubview:signTextField];
[signTextField becomeFirstResponder];
textString = signTextField.text;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldDidChange:) name:UITextFieldTextDidChangeNotification object:nil];
}
- (void)setNavigationBar{
self.navigationItem.title = @"昵称";
UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc]initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(doSave:)];
rightBarButton.tintColor = [UIColor whiteColor];
self.navigationItem.rightBarButtonItem = rightBarButton;
}
- (void)textFieldDidChange:(NSNotification *)notification{
if (signTextField.text.length > 14) {
signTextField.text = textString;
}
else{
textString = signTextField.text;
}
}
- (void)doSave:(UIBarButtonItem *)barBtnItem{
if (signTextField.text.length > 0) {
barBtnItem.enabled = NO;
[HUDUtil showLoading];
[[IVTNetworkAPIClient sharedClient] modifyNickName:[signTextField.text base64EncodedFromString] success:^(NSDictionary *successData) {
[IVTAccountTool setNickName:[signTextField.text base64EncodedFromString]];
[[NSNotificationCenter defaultCenter] postNotificationName:@"successToChangeNickName" object:nil];
if (self.editSuccessBlock) {
self.editSuccessBlock(signTextField.text);
}
[HUDUtil showSuccess:@"修改成功"];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.navigationController popViewControllerAnimated:YES];
});
} error:^(NSDictionary *successData) {
NSString *msg = successData[@"description"];
[HUDUtil showError:msg];
barBtnItem.enabled = YES;
} failure:^(NSError *failureError) {
[HUDUtil showError:@"网络异常"];
barBtnItem.enabled = YES;
}];
}
else{
[HUDUtil showInfo:@"昵称不能为空"];
}
}
- (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