Message_Set_VC.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 configNavBar];
  22. [_sureButton setTitleColor:defGreen forState:UIControlStateNormal];
  23. [_giveUpBtn setTitleColor:defGreen forState:UIControlStateNormal];
  24. self.pwdTextField.delegate = self;
  25. _pwdTextField.secureTextEntry = YES;
  26. }
  27. //明暗文切换
  28. - (IBAction)eyeBtnClick:(id)sender {
  29. _pwdTextField.secureTextEntry = _pwdTextField.secureTextEntry ? NO : YES;
  30. }
  31. //确定修改
  32. - (IBAction)sureBtnClick:(id)sender {
  33. if (![Util connectedToNetWork]) {
  34. showMsgUnconnect();
  35. return;
  36. }
  37. //判断密码长度
  38. if (_pwdTextField.text.length < 6) {
  39. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"密码长度不能少于6个字符" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
  40. [alert show];
  41. return;
  42. }
  43. NSMutableArray *arr=[NSMutableArray array];
  44. [arr addPro:@"loginCode" Value:self.loginCode];
  45. [arr addPro:@"pwd" Value:_pwdTextField.text];
  46. [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
  47. NSString* method = @"saveCoachPwd";
  48. ShowHUD();
  49. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  50. RemoveHUD();
  51. //NSLog(@"密码返回数据->%@",root);
  52. if (!root)
  53. {
  54. ShowMsgFailed();
  55. return;
  56. }
  57. if ( 1 == [root[@"code"] integerValue]) {
  58. ShowMsg(root[@"body"]);
  59. return;
  60. }
  61. ShowMsg(@"修改成功,请登录!");
  62. }];
  63. //回到登录页
  64. [self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
  65. }
  66. //放弃修改
  67. - (IBAction)giveUpBtnClick:(id)sender {
  68. //回到登录页
  69. [self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
  70. }
  71. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  72. {
  73. [super touchesBegan:touches withEvent:event];
  74. if ([_pwdTextField isFirstResponder]) {
  75. [_pwdTextField resignFirstResponder];
  76. }
  77. }
  78. #pragma mark - 限制输入字符
  79. //输入限制
  80. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;
  81. {
  82. //先设置只能输入的集合 invertedSet就是将咱们允许输入的字符串的字符找出
  83. NSCharacterSet *canInputSet = [[NSCharacterSet characterSetWithCharactersInString:kAlphaNum] invertedSet];
  84. //把允许输入的内容转化成数组,再转化成字符串
  85. NSString *str = [[string componentsSeparatedByCharactersInSet:canInputSet] componentsJoinedByString:@""];
  86. //判断输入的字符是否包含在允许输入的字符之内
  87. BOOL isSuccess = [string isEqualToString:str];
  88. //限制文本框输入内容的长度不得超过10且有输入内容的限制
  89. if (textField.text.length <= 20 && isSuccess){
  90. //返回值为YES的时候,文本框可以进行编辑
  91. return YES;
  92. }else{
  93. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"密码不能超出20位" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alert show];
  94. //当返回NO的时候,文本框内的内容不会在再改变,甚至不能进行删除
  95. return NO;
  96. }
  97. }
  98. - (void)didReceiveMemoryWarning {
  99. [super didReceiveMemoryWarning];
  100. // Dispose of any resources that can be recreated.
  101. }
  102. /*
  103. #pragma mark - Navigation
  104. // In a storyboard-based application, you will often want to do a little preparation before navigation
  105. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  106. // Get the new view controller using [segue destinationViewController].
  107. // Pass the selected object to the new view controller.
  108. }
  109. */
  110. @end