单军华
2018-03-29 89d748b77b478905732e60f0b4c5807c274b6565
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
//
//  ChangeNamePage.m
//  airtree
//
//  Created by WindShan on 2016/11/11.
//  Copyright © 2016年 Gloria. All rights reserved.
//
 
#import "ChangeNamePage.h"
#import "GloriaLabel.h"
#import "CommonReqModel.h"
#import "NetworkSingleton.h"
 
 
@interface ChangeNamePage ()
{
    UITextField * userNickNameTextField;
    
    UIButton * resetUserNameBtn;
 
    
}
@end
 
@implementation ChangeNamePage
 
 
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"修改昵称";
    //[self setNavigationLeft:@"返回" sel:@selector(backAction)];
    
    userNickNameTextField = [[UITextField alloc] initWithFrame:CGRectMake(30, 40, SCREEN_WIDTH-60, 35)];
    userNickNameTextField.secureTextEntry = NO;
    userNickNameTextField.placeholder = @"请输入新的昵称";
    userNickNameTextField.font = [UIFont fontWithName:@"Arial" size:16];
    userNickNameTextField.delegate = self;
    userNickNameTextField.layer.borderColor = [RgbColor(213, 213, 213) CGColor];
    userNickNameTextField.layer.masksToBounds=YES;
    userNickNameTextField.layer.cornerRadius=5.0f;
    userNickNameTextField.layer.borderWidth= 1.0f;
    userNickNameTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    // 设置一个空白blankView,15.0就是这块View的宽度width,也是光标的位置,根据你自己的需要设定大小
    userNickNameTextField.leftView = [[UIView alloc] initWithFrame:CGRectMake(userNickNameTextField.frame.origin.x,userNickNameTextField.frame.origin.y,10.0, userNickNameTextField.frame.size.height)];
    userNickNameTextField.leftViewMode =UITextFieldViewModeAlways;
    [self.view addSubview:userNickNameTextField];
 
    
    resetUserNameBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    resetUserNameBtn.frame = CGRectMake(30,90, SCREEN_WIDTH-60, 40);
    [resetUserNameBtn setTitle:@"提交修改" forState:UIControlStateNormal];
    resetUserNameBtn.backgroundColor = kUIColorFromRGB(0x00b744);
    resetUserNameBtn.titleLabel.font = [UIFont systemFontOfSize: 18.0];
    [resetUserNameBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    resetUserNameBtn.layer.masksToBounds=YES;
    resetUserNameBtn.layer.cornerRadius=5.0f;
    [resetUserNameBtn addTarget:self action:@selector(resetUserNameAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:resetUserNameBtn];
    
    if (_loginUser[@"nickname"] != nil) {
        [userNickNameTextField setText:_loginUser[@"nickname"]];
    }
    
    
}
 
-(void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
}
 
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    
    self.navigationController.navigationBarHidden = NO;
    
}
 
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:YES];
    
    resetUserNameBtn.userInteractionEnabled = YES;
    resetUserNameBtn.alpha = 1;
}
 
#pragma mark custom function begin
////倒计时提醒
# pragma mark custom function end
 
 
#pragma mark button event begin
-(void)resetUserNameAction
{
    // 重置昵称操作
    if(userNickNameTextField.text.length == 0)
    {
        [Global alertMessageEx:@"请输入昵称." title:@"提示信息" okTtitle:nil cancelTitle:@"OK"  delegate:self];
    }
    else
    {
        //, _loginUser[@"_id"]
        NSString *path = [NSString stringWithFormat:UPDATE_NAME];
    
        CommonReqModel * model = [[CommonReqModel alloc] init];
        model.userID = _loginUser[@"_id"];
        model.nickname = userNickNameTextField.text;
        
        MPWeakSelf(self);
        [NetworkSingleton networkingPostMethod:model.toDic urlName:path success:^(id responseBody)
         {
             MPStrongSelf(self);
             BaseResModel * resModel = [Global toBaseModel:responseBody];
             if(resModel.code == 0)
             {
                 [_loginUser setObject:userNickNameTextField.text forKey:@"nickname"];
                 [UserDefault setObject:userNickNameTextField.text forKey:@"nickname"];
                 [UserDefault synchronize];
                 
                 [Global alertMessageEx:@"昵称修改成功!" title:@"提示信息" okTtitle:nil cancelTitle:@"OK"  delegate:self];
                 // 最外层控制器出栈
                 [weakself.navigationController popViewControllerAnimated:YES];
             }
             else
             {
                 [Global alertMessageEx:resModel.desc title:@"昵称修改失败" okTtitle:nil cancelTitle:@"OK" delegate:self];
             }
         }
          failure:^(NSString *error)
         {
             [Global alertMessageEx:error title:@"昵称修改失败" okTtitle:nil cancelTitle:@"OK" delegate:self];
         }];
    }
}
#pragma mark button event end
 
#pragma mark disappear keyboard begin
 
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if ([textField isFirstResponder]) {
        [textField resignFirstResponder];
    }
    return true;
}
 
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self textFieldShouldReturn:userNickNameTextField];
}
 
#pragma mark disappear keyboard end
 
 
 
- (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