//
|
// 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
|