热更新demo

modifyAddressController.m 5.1KB

    // // modifyAddressController.m // ThePaperBase // // Created by Huixin on 15/12/23. // Copyright © 2015年 scar1900. All rights reserved. // #import "modifyAddressController.h" @interface modifyAddressController () <UITextViewDelegate> @property(nonatomic, strong)UITextView *addressView; @property(nonatomic, strong)TPCustomButton *confirmButton; @end @implementation modifyAddressController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; self.titleStr =@"修改地址"; UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)]; [self.view addGestureRecognizer:tapGesture]; [self.view addSubview:self.addressView]; [self.view addSubview:self.confirmButton]; [self.addressView becomeFirstResponder]; [self layoutViews]; } - (void)layoutViews { [self.addressView makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.naviBar.bottom).offset(32); make.left.equalTo(self.view.left).offset(20); make.right.equalTo(self.view.right).offset(-20); make.height.mas_equalTo(@150); }]; [self.confirmButton makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.addressView.bottom).offset(24); make.left.equalTo(self.addressView.left); make.right.equalTo(self.addressView.right); make.height.equalTo(self.confirmButton.width).multipliedBy(0.15); }]; } - (UITextView*)addressView { if (!_addressView) { _addressView = [[UITextView alloc] init]; _addressView.layer.cornerRadius = 5; _addressView.layer.borderWidth =1; _addressView.font = appFont(TEXT_FOUR_LEVELSIZE, NO); _addressView.textColor = [UIColor colorWithHexString:TextBlack]; _addressView.layer.borderColor = [UIColor colorWithHexString:LINECOLOR].CGColor; if ([[TPUserDefault instance].isNightMode intValue] > 0) _addressView.keyboardAppearance = UIKeyboardAppearanceDark; else _addressView.keyboardAppearance = UIKeyboardAppearanceDefault; _addressView.keyboardType = UIKeyboardTypeDefault; _addressView.delegate = self; _addressView.backgroundColor = [UIColor clearColor]; } return _addressView; } - (TPCustomButton*)confirmButton { if (!_confirmButton) { _confirmButton = [[TPCustomButton alloc] init]; _confirmButton.title = @"确认"; [_confirmButton addTarget:self action:@selector(confirm) forControlEvents:UIControlEventTouchUpInside]; } return _confirmButton; } - (void)setOriginStr:(NSString *)originStr { _originStr = originStr; self.addressView.text = originStr; } #pragma mark - textview delegate - (void)textViewDidChange:(UITextView *)textView { if ([textView.text isMatchedByRegex:@"[^\\u0020-\\u007E\\u00A0-\\u00BE\\u2E80-\\uA4CF\\uF900-\\uFAFF\\uFE30-\\uFE4F\\uFF00-\\uFFEF\\u0080-\\u009F\\u2000-\\u201f\r\n]"]) { textView.text = disable_emoji(textView.text); } if (textView.text.length > 400) textView.text = [textView.text substringToIndex:400]; _originStr = textView.text; } - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { if ([textView isFirstResponder]) { if ([[[textView textInputMode] primaryLanguage] isEqualToString:@"emoji"] || ![[textView textInputMode] primaryLanguage]) { return NO; } } return YES; } #pragma mark - button event handler - (void)confirm { [self closeKeyBoard]; NSDictionary *dic = @{@"address":self.originStr}; [Remote doJsonAction:0 requestUrl:editUserInfoURL parameter:dic delegate:self]; } #pragma mark - remote delegate - (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responseData { if (actionTag == 0) { userBO *user = setJsonDicToDataModel(responseData[@"userInfo"], [userBO class]); NSString *lastLoginType = [TPUserDefault instance].userBO.loginType; user.loginType = lastLoginType; [TPUserDefault instance].userBO = user; [self.navigationController popViewControllerAnimated:YES]; } } - (void)remoteResponsFailed:(int)actionTag withMessage:(NSString *)message resultCode:(NSString *)code{ ShowTextMessage(message); } #pragma mark - tap handler - (void)tap:(id)sender { [self closeKeyBoard]; } #pragma mark - keyBoard event - (void)closeKeyBoard { [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end