// // Message_Set_VC.m // jiaPei // // Created by EchoShacolee on 2017/1/17. // Copyright © 2017年 JCZ. All rights reserved. // #import "Message_Set_VC.h" #define kAlphaNum @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+..<>{}[];:/?\'|"//限制输入字符类型 @interface Message_Set_VC () @property (weak, nonatomic) IBOutlet UITextField *pwdTextField; @property (weak, nonatomic) IBOutlet UIButton *eyeButton; @property (weak, nonatomic) IBOutlet UIButton *sureButton; @property (weak, nonatomic) IBOutlet UIButton *giveUpBtn; @end @implementation Message_Set_VC - (void)viewDidLoad { [super viewDidLoad]; self.title = @"设置新密码"; self.view.backgroundColor = backGroundColor; [self configNavigationBar]; [_sureButton setTitleColor:defGreen forState:UIControlStateNormal]; [_giveUpBtn setTitleColor:defGreen forState:UIControlStateNormal]; self.pwdTextField.delegate = self; _pwdTextField.secureTextEntry = YES; } //明暗文切换 - (IBAction)eyeBtnClick:(id)sender { _pwdTextField.secureTextEntry = _pwdTextField.secureTextEntry ? NO : YES; } //确定修改 - (IBAction)sureBtnClick:(id)sender { if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } //判断密码长度 if (_pwdTextField.text.length < 6) { [RQ_SHARE_FUNCTION showAlertWithTitle:nil message:@"密码长度不能少于6个字符" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil completion:nil]; return; } NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"loginCode" Value:self.loginCode]; [arr addPro:@"pwd" Value:_pwdTextField.text]; [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]]; NSString* method = @"savePwd"; ShowHUD(); [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) { RemoveHUD(); //NSLog(@"密码返回数据->%@",root); if (!root) { ShowMsgFailed(); return; } if ( 1 == [root[@"code"] integerValue]) { ShowMsg(root[@"body"]); return; } ShowMsg(@"修改成功,请登录!"); }]; //回到登录页 [[RQ_SHARE_FUNCTION topViewController] dismissViewControllerAnimated:NO completion:nil]; } //放弃修改 - (IBAction)giveUpBtnClick:(id)sender { //回到登录页 [[RQ_SHARE_FUNCTION topViewController] dismissViewControllerAnimated:NO completion:nil]; } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event]; if ([_pwdTextField isFirstResponder]) { [_pwdTextField resignFirstResponder]; } } #pragma mark - 限制输入字符 //输入限制 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string; { //先设置只能输入的集合 invertedSet就是将咱们允许输入的字符串的字符找出 NSCharacterSet *canInputSet = [[NSCharacterSet characterSetWithCharactersInString:kAlphaNum] invertedSet]; //把允许输入的内容转化成数组,再转化成字符串 NSString *str = [[string componentsSeparatedByCharactersInSet:canInputSet] componentsJoinedByString:@""]; //判断输入的字符是否包含在允许输入的字符之内 BOOL isSuccess = [string isEqualToString:str]; //限制文本框输入内容的长度不得超过10且有输入内容的限制 if (textField.text.length <= 20 && isSuccess){ //返回值为YES的时候,文本框可以进行编辑 return YES; }else{ [RQ_SHARE_FUNCTION showAlertWithTitle:nil message:@"密码不能超出20位" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil completion:nil]; //当返回NO的时候,文本框内的内容不会在再改变,甚至不能进行删除 return NO; } } - (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