NewModifyPhoneViewController.m 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. //
  2. // MMMessageVerificationVC.m
  3. // MingMen
  4. //
  5. // Created by 肖雨 on 2017/3/11.
  6. // Copyright © 2017年 肖雨. All rights reserved.
  7. //
  8. #import "NewModifyPhoneViewController.h"
  9. #import "NewRegistCell.h"
  10. @interface NewModifyPhoneViewController ()<UITableViewDelegate,UITableViewDataSource>
  11. {
  12. NSMutableArray *dataArray;
  13. UITableView *mainTableView;
  14. UITextField *phoneTextField;
  15. UITextField *verificationCodeTextField;
  16. UIButton *verificationCodeButton;
  17. }
  18. @end
  19. @implementation NewModifyPhoneViewController
  20. -(void)dealloc
  21. {
  22. NSLog(@"修改手机号界面销毁");
  23. }
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. // Do any additional setup after loading the view.
  27. [self setNavTitle:@"修改手机号"];
  28. [self dataInitialization];
  29. [self loadsView];
  30. }
  31. #pragma mark - 数据初始化
  32. -(void)dataInitialization
  33. {
  34. phoneTextField = nil;
  35. verificationCodeTextField = nil;
  36. verificationCodeButton = nil;
  37. dataArray = NewMutableArrayInit;
  38. for (int i=0; i<2; i++) {
  39. NSDictionary *dataDic = [NSDictionary dictionary];
  40. switch (i) {
  41. case 0:
  42. dataDic = @{@"nameKey":@"手机号",@"imageKey":@"手机号码",@"placeholderKey":@"请输入新的手机号"};
  43. [dataArray addObject:dataDic];
  44. break;
  45. case 1:
  46. dataDic = @{@"nameKey":@"验证码",@"imageKey":@"短信",@"placeholderKey":@"请输入短信验证码"};
  47. [dataArray addObject:dataDic];
  48. break;
  49. default:
  50. break;
  51. }
  52. }
  53. }
  54. #pragma mark - UI初始化
  55. -(void)loadsView
  56. {
  57. [self.view addSubview:mainTableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, ViewStartY, SCREEN_WIDTH, SCREEN_HEIGHT-ViewStartY) backgroundColor:NewWhiteColor style:0 delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:100 userInteractionEnabled:YES]];
  58. UIView *view;
  59. mainTableView.tableFooterView = view = [NewControlPackage viewInitWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 84) backgroundColor:NewClearColor hidden:NO tag:101 userInteractionEnabled:YES];
  60. UIImageView *lineImge;
  61. [view addSubview:lineImge = [NewControlPackage imageViewInitWithFrame:CGRectMake(15, 0, SCREEN_WIDTH-15, .6) image:nil highlightedImage:nil backgroundColor:NewCellLineColor tag:102 hidden:NO userInteractionEnabled:YES]];
  62. UIButton *confirm;
  63. [view addSubview:confirm = [NewControlPackage buttonInitWithTitle:@"确定" Frame:CGRectMake(20, 40, SCREEN_WIDTH-40, 36) backgroundImage:nil backgroundImageHighlighted:nil backgroundColor:NewNavigationColor textColor:NewWhiteColor textAlignment:UIControlContentHorizontalAlignmentCenter font:NewFont(14) tag:105 target:self action:@selector(touchConfirm) hidden:NO userInteractionEnabled:YES]];
  64. ViewRadius(confirm, 8);
  65. }
  66. #pragma mark - UITableView Delegate
  67. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  68. return 1;
  69. }
  70. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  71. return dataArray.count;
  72. }
  73. - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  74. static NSString *Cell = @"Cell";
  75. NewRegistCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
  76. if (cell == nil) {
  77. cell = [[NewRegistCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
  78. }
  79. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  80. cell.accessoryType = UITableViewCellAccessoryNone;
  81. cell.image.image = NewImageNamed(dataArray[indexPath.row][@"imageKey"]);
  82. cell.title.text = dataArray[indexPath.row][@"nameKey"];
  83. if (verificationCodeTextField == nil) {
  84. //获取验证码frame
  85. float vcwidth = 66;
  86. float vcheight = cell.height-20;
  87. float vcx = SCREEN_WIDTH-vcwidth-20;
  88. float vcy = 10;
  89. //输入框frame
  90. float tx = 110;
  91. float ty = 2;
  92. float twidth = SCREEN_WIDTH-tx-20;
  93. float theight = cell.height-2;
  94. UITextField *textField;
  95. [cell.contentView addSubview:textField = [NewControlPackage textFieldInitWithFrame:CGRectMake(tx, ty, twidth, theight) backgroundImage:nil backgroundColor:NewClearColor textColor:NewGrayColor placeholder:dataArray[indexPath.row][@"placeholderKey"] hidden:NO tag:100+(int)indexPath.row font:NewFont(14) textAlignment:NSTextAlignmentLeft clearButtonMode:NO clearsOnBeginEditing:NO adjustsFontSizeToFitWidth:NO secureTextEntry:NO keyboardType:UIKeyboardTypeDefault returnKeyType:UIReturnKeyDefault userInteractionEnabled:YES]];
  96. [textField addTarget:self action:@selector(textFieldEditingChanged:) forControlEvents:UIControlEventEditingChanged];
  97. if (indexPath.row==0) {
  98. phoneTextField = textField;
  99. //phoneTextField.keyboardType = UIKeyboardTypeNumberPad;
  100. }else if (indexPath.row==1) {
  101. verificationCodeTextField = textField;
  102. [cell.contentView addSubview:verificationCodeButton = [NewControlPackage buttonInitWithTitle:@"获取验证码" Frame:CGRectMake(vcx, vcy, vcwidth, vcheight) backgroundImage:nil backgroundImageHighlighted:nil backgroundColor:NewLightGrayColor textColor:NewWhiteColor textAlignment:UIControlContentHorizontalAlignmentCenter font:NewFont(10) tag:99 target:self action:@selector(touchVerificationCode:) hidden:NO userInteractionEnabled:YES]];
  103. ViewRadius(verificationCodeButton, 10);
  104. }
  105. }
  106. return cell;
  107. }
  108. #pragma mark - 作字符输入限制
  109. - (void)textFieldEditingChanged:(UITextField *)textField
  110. {
  111. if (textField == phoneTextField) {
  112. if ([textField.text length]>11) {
  113. textField.text=[textField.text substringToIndex:11];//手机号码11位
  114. }
  115. }else if (textField == verificationCodeTextField) {
  116. if ([textField.text length]>4) {
  117. textField.text=[textField.text substringToIndex:4];//验证码4位
  118. }
  119. }
  120. }
  121. #pragma mark - 获取验证码
  122. - (void)touchVerificationCode:(UIButton *)sender
  123. {
  124. if (![self verification:nil]) {
  125. return;
  126. }
  127. sender.frame = CGRectMake(sender.left, sender.top, 80, sender.height);
  128. [self verificationCode:60 sender:sender];
  129. }
  130. - (void)verificationCode:(NSInteger)code sender:(UIButton *)sender{
  131. NSString *str=[NSString stringWithFormat:@"%d秒后重新发送",(int)code];
  132. [sender setTitle:str forState:UIControlStateNormal];
  133. sender.enabled=NO;
  134. if (code==0) {
  135. sender.enabled=YES;
  136. [sender setTitle:@"获取验证码" forState:UIControlStateNormal];
  137. sender.frame = CGRectMake(sender.left, sender.top, 66, sender.height);
  138. return;
  139. }
  140. code--;
  141. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  142. [self verificationCode:code sender:sender];
  143. });
  144. }
  145. #pragma mark - 确定
  146. - (void)touchConfirm
  147. {
  148. if ([self verification:@"已下发短信验证码"]) {
  149. }
  150. };
  151. - (BOOL)verification:(NSString *)status
  152. {
  153. if (phoneTextField.text.length <= 0) {
  154. [self.view makeToast:@"手机号码输入有误" duration:1.5 position:CSToastPositionCenter];
  155. return NO;
  156. }
  157. if ([status isEqualToString:@"已下发短信验证码"]) {
  158. if (verificationCodeTextField.text.length <= 0) {
  159. [self.view makeToast:@"验证码输入有误" duration:1.5 position:CSToastPositionCenter];
  160. return NO;
  161. }
  162. }
  163. return YES;
  164. }
  165. - (void)didReceiveMemoryWarning {
  166. [super didReceiveMemoryWarning];
  167. // Dispose of any resources that can be recreated.
  168. }
  169. /*
  170. #pragma mark - Navigation
  171. // In a storyboard-based application, you will often want to do a little preparation before navigation
  172. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  173. // Get the new view controller using [segue destinationViewController].
  174. // Pass the selected object to the new view controller.
  175. }
  176. */
  177. @end