Message_Set_VC.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. // Message_Set_VC.m
  3. // jiaPei
  4. //
  5. // Created by EchoShacolee on 2017/1/17.
  6. // Copyright © 2017年 JCZ. All rights reserved.
  7. //
  8. #import "Message_Set_VC.h"
  9. #define kAlphaNum @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+..<>{}[];:/?\'|"//限制输入字符类型
  10. @interface Message_Set_VC ()<UITextFieldDelegate>
  11. @property (weak, nonatomic) IBOutlet UITextField *pwdTextField;
  12. @property (weak, nonatomic) IBOutlet UIButton *eyeButton;
  13. @property (weak, nonatomic) IBOutlet UIButton *sureButton;
  14. @property (weak, nonatomic) IBOutlet UIButton *giveUpBtn;
  15. @end
  16. @implementation Message_Set_VC
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.title = @"设置新密码";
  20. self.view.backgroundColor = backGroundColor;
  21. [self configNavigationBar];
  22. [_sureButton setTitleColor:defGreen forState:UIControlStateNormal];
  23. [_giveUpBtn setTitleColor:defGreen forState:UIControlStateNormal];
  24. self.pwdTextField.delegate = self;
  25. _pwdTextField.secureTextEntry = YES;
  26. [_eyeButton setImage:[UIImage imageNamed:@"closeEye"] forState:UIControlStateNormal];
  27. [_eyeButton setImage:[UIImage imageNamed:@"passEye"] forState:UIControlStateSelected];}
  28. //明暗文切换
  29. - (IBAction)eyeBtnClick:(id)sender {
  30. _eyeButton.selected = !_eyeButton.isSelected;
  31. _pwdTextField.secureTextEntry = _pwdTextField.secureTextEntry ? NO : YES;
  32. }
  33. //确定修改
  34. - (IBAction)sureBtnClick:(id)sender {
  35. if (![Util connectedToNetWork]) {
  36. showMsgUnconnect();
  37. return;
  38. }
  39. //判断密码长度
  40. if (_pwdTextField.text.length < 6) {
  41. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"密码长度不能少于6个字符" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
  42. [alert show];
  43. return;
  44. }
  45. NSMutableArray *arr=[NSMutableArray array];
  46. [arr addPro:@"loginCode" Value:self.loginCode];
  47. [arr addPro:@"pwd" Value:_pwdTextField.text];
  48. [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]];
  49. NSString* method = @"savePwdN";
  50. [MBProgressHUD showLoadToView:self.view];
  51. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  52. [MBProgressHUD hideHUDForView:self.view];
  53. //NSLog(@"密码返回数据->%@",root);
  54. if (!root)
  55. {
  56. ShowMsgFailed();
  57. return;
  58. }
  59. if ( 1 == [root[@"code"] integerValue]) {
  60. ShowMsg(root[@"body"]);
  61. return;
  62. }
  63. showMsgByAlertWithSureBlock(self, @"密码重置成功", ^{
  64. //回到登录页
  65. [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
  66. });
  67. }];
  68. }
  69. //放弃修改
  70. - (IBAction)giveUpBtnClick:(id)sender {
  71. //回到登录页
  72. [self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
  73. }
  74. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  75. {
  76. [super touchesBegan:touches withEvent:event];
  77. if ([_pwdTextField isFirstResponder]) {
  78. [_pwdTextField resignFirstResponder];
  79. }
  80. }
  81. #pragma mark - 限制输入字符
  82. //输入限制
  83. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;
  84. {
  85. //先设置只能输入的集合 invertedSet就是将咱们允许输入的字符串的字符找出
  86. NSCharacterSet *canInputSet = [[NSCharacterSet characterSetWithCharactersInString:kAlphaNum] invertedSet];
  87. //把允许输入的内容转化成数组,再转化成字符串
  88. NSString *str = [[string componentsSeparatedByCharactersInSet:canInputSet] componentsJoinedByString:@""];
  89. //判断输入的字符是否包含在允许输入的字符之内
  90. BOOL isSuccess = [string isEqualToString:str];
  91. //限制文本框输入内容的长度不得超过10且有输入内容的限制
  92. if (textField.text.length <= 20 && isSuccess){
  93. //返回值为YES的时候,文本框可以进行编辑
  94. return YES;
  95. }else{
  96. if (!isSuccess) {
  97. return NO;
  98. }else{
  99. if (str.length == 0) {
  100. return YES;//保证删除功能
  101. }
  102. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"密码不能超出20位" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alert show];
  103. return NO;
  104. }
  105. //当返回NO的时候,文本框内的内容不会在再改变
  106. return NO;
  107. }
  108. }
  109. - (void)didReceiveMemoryWarning {
  110. [super didReceiveMemoryWarning];
  111. // Dispose of any resources that can be recreated.
  112. }
  113. /*
  114. #pragma mark - Navigation
  115. // In a storyboard-based application, you will often want to do a little preparation before navigation
  116. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  117. // Get the new view controller using [segue destinationViewController].
  118. // Pass the selected object to the new view controller.
  119. }
  120. */
  121. @end