JXSetShikuNumVC.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //
  2. // JXSetShikuNumVC.m
  3. // shiku_im
  4. //
  5. // Created by p on 2019/4/11.
  6. // Copyright © 2019年 Reese. All rights reserved.
  7. //
  8. #import "JXSetShikuNumVC.h"
  9. #define HEIGHT 50
  10. @interface JXSetShikuNumVC () <UITextFieldDelegate>
  11. @property (nonatomic, strong) UITextField *textField;
  12. @property (nonatomic, strong) UIView *baseView;
  13. @end
  14. @implementation JXSetShikuNumVC
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. // Do any additional setup after loading the view.
  18. self.isGotoBack = YES;
  19. self.title = [NSString stringWithFormat:@"%@%@",Localized(@"JXSettingVC_Set"),Localized(@"JX_Communication")];
  20. self.heightFooter = 0;
  21. self.heightHeader = JX_SCREEN_TOP;
  22. //self.view.frame = CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT);
  23. [self createHeadAndFoot];
  24. self.tableBody.backgroundColor = HEXCOLOR(0xF2F2F2);
  25. self.tableBody.scrollEnabled = YES;
  26. self.baseView = [[UIView alloc] initWithFrame:CGRectMake(15, 10, JX_SCREEN_WIDTH-30, 270)];
  27. self.baseView.backgroundColor = [UIColor whiteColor];
  28. self.baseView.layer.masksToBounds = YES;
  29. self.baseView.layer.cornerRadius = 7.f;
  30. [self.tableBody addSubview:self.baseView];
  31. UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 30, 44, 44)];
  32. imageView.layer.cornerRadius = imageView.frame.size.width / 2;
  33. imageView.layer.masksToBounds = YES;
  34. [g_server getHeadImageLarge:g_myself.userId userName:g_myself.userNickname imageView:imageView];
  35. [self.baseView addSubview:imageView];
  36. UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(imageView.frame) + 15, imageView.frame.origin.y, 200, imageView.frame.size.height)];
  37. name.font = [UIFont systemFontOfSize:15.0];
  38. name.text = g_myself.userNickname;
  39. [self.baseView addSubview:name];
  40. _textField = [[UITextField alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(imageView.frame) + 30, self.baseView.frame.size.width - 30, 40)];
  41. _textField.delegate = self;
  42. _textField.layer.masksToBounds = YES;
  43. _textField.layer.cornerRadius = 7.f;
  44. [_textField becomeFirstResponder];
  45. _textField.backgroundColor = HEXCOLOR(0xF6F7F9);
  46. _textField.keyboardType = UIKeyboardTypeASCIICapable;
  47. [self.baseView addSubview:_textField];
  48. UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
  49. _textField.leftView = leftView;
  50. _textField.leftViewMode = UITextFieldViewModeAlways;
  51. UILabel *tip = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(_textField.frame)+10, _textField.frame.size.width, 13)];
  52. tip.font = [UIFont systemFontOfSize:13.0];
  53. tip.textColor = HEXCOLOR(0x999999);
  54. tip.text = Localized(@"JX_CommunicationOnlySetOne");
  55. [self.baseView addSubview:tip];
  56. UIButton* _btn = [UIFactory createCommonButton:Localized(@"JX_Confirm") target:self action:@selector(onConfirm)];
  57. _btn.layer.cornerRadius = 7;
  58. _btn.clipsToBounds = YES;
  59. _btn.custom_acceptEventInterval = 1.0f;
  60. _btn.titleLabel.font = SYSFONT(16);
  61. _btn.frame = CGRectMake(15, CGRectGetMaxY(tip.frame) + 30, self.baseView.frame.size.width - 30, 40);
  62. [self.baseView addSubview:_btn];
  63. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
  64. [self.tableBody addGestureRecognizer:tap];
  65. }
  66. - (void)tapAction{
  67. [self.view endEditing:YES];
  68. }
  69. - (void)onConfirm {
  70. self.user.account = _textField.text;
  71. g_myself.account = self.user.account;
  72. [g_server updateShikuNum:self.user toView:self];
  73. }
  74. -(BOOL)textField:(UITextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*)string{
  75. NSUInteger lengthOfString = string.length;//lengthOfString的值始终为1
  76. for(NSInteger loopIndex =0; loopIndex < lengthOfString; loopIndex++) {
  77. unichar character = [string characterAtIndex:loopIndex];
  78. //将输入的值转化为ASCII值(即内部索引值),可以参考ASCII表            // 48-57;{0,9};65-90;{A..Z};97-122:{a..z}
  79. if(character <48) return NO;// 48 unichar for 0
  80. if(character >57&& character <65) return NO;
  81. if(character >90&& character <97) return NO;
  82. if(character >122) return NO;
  83. }
  84. return YES;
  85. }
  86. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  87. [_wait stop];
  88. if( [aDownload.action isEqualToString:act_UserUpdate] ){
  89. self.user.setAccountCount = [NSString stringWithFormat:@"%ld",([g_myself.setAccountCount integerValue] + 1)];
  90. g_myself.setAccountCount = self.user.setAccountCount;
  91. if ([self.delegate respondsToSelector:@selector(setShikuNum:updateSuccessWithAccount:)]) {
  92. [self.delegate setShikuNum:self updateSuccessWithAccount:self.user.account];
  93. [self actionQuit];
  94. }
  95. }
  96. }
  97. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  98. [_wait stop];
  99. return show_error;
  100. }
  101. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  102. [_wait stop];
  103. return show_error;
  104. }
  105. -(void) didServerConnectStart:(JXConnection*)aDownload{
  106. [_wait start];
  107. }
  108. /*
  109. #pragma mark - Navigation
  110. // In a storyboard-based application, you will often want to do a little preparation before navigation
  111. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  112. // Get the new view controller using [segue destinationViewController].
  113. // Pass the selected object to the new view controller.
  114. }
  115. */
  116. @end