Message_Set_VC.m 4.5 KB

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