// // EditMySignOrBriefVC.m // smartRhino // // Created by armin on 2019/11/1. // Copyright © 2019 tederen. All rights reserved. // #import "EditMySignOrBriefVC.h" #import "UIPlaceHolderTextView.h" @interface EditMySignOrBriefVC () @property (strong,nonatomic) IBOutlet UILabel *pageTitleLabel; @property (strong,nonatomic) IBOutlet UIButton *okBtn; @property (strong,nonatomic) IBOutlet UIPlaceHolderTextView *editTextView; @end @implementation EditMySignOrBriefVC +(EditMySignOrBriefVC *)initEditMySignOrBriefVC{ EditMySignOrBriefVC *controller = [StoryboardManager.shared.myCenter instantiateViewControllerWithIdentifier:@"EditMySignOrBriefVC"]; return controller; } - (void)viewDidLoad { [super viewDidLoad]; self.fd_prefersNavigationBarHidden = YES; self.editTextView.delegate = self; if(self.pagetype == EditMySignOrBriefPageType1){ self.pageTitleLabel.text = @"我的签名"; self.editTextView.text = [AppUserModel sharedAppUserModel].Signature; if (self.editTextView.text.length == 0) { self.editTextView.placeholder = @"我的签名"; } }else if(self.pagetype == EditMySignOrBriefPageType2){ self.pageTitleLabel.text = @"自我介绍"; self.editTextView.text = [AppUserModel sharedAppUserModel].Description; if (self.editTextView.text.length == 0) { self.editTextView.placeholder = @"自我介绍"; } }else{ self.pageTitleLabel.text = @"我的昵称"; self.editTextView.text = [AppUserModel sharedAppUserModel].Nick; if (self.editTextView.text.length == 0) { self.editTextView.placeholder = @"我的昵称"; } } NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new]; paragraphStyle.lineSpacing = 12;// 字体的行间距 NSDictionary *attributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSParagraphStyleAttributeName:paragraphStyle }; self.editTextView.typingAttributes = attributes; WEAKSELF [self.okBtn setAction:^{ STRONGSELF if(strongSelf.pagetype == EditMySignOrBriefPageType1){ [strongSelf commitData]; }else if(strongSelf.pagetype == EditMySignOrBriefPageType2){ [strongSelf commitData2]; }else{ [strongSelf commitData3]; } }]; } - (void)commitData{ WEAKSELF SHOWLOADING NSString *modyUrl = [NSString stringWithFormat:@"%@%@",BaseUrl,UpdateUserInfoPUT]; [[HttpManager sharedHttpManager] PUTUrl:modyUrl parameters:@{@"signature":self.editTextView.text} success:^(id _Nonnull responseObject) { [UserManager getUserInfoDetailSuccess:^(id _Nonnull responseObject) { REMOVESHOW STRONGSELF [strongSelf.navigationController popViewControllerAnimated:YES]; } failure:^(NSError * _Nonnull error) { REMOVESHOW SHOWERROR([ZYCTool handerResultData:error]) }]; NSLog(@"成功"); } failure:^(NSError * _Nonnull error) { REMOVESHOW NSLog(@"失败"); SHOWERROR([ZYCTool handerResultData:error]) }]; } - (void)commitData2{ if (self.editTextView.text.length == 0) { SHOWERROR(@"内容不能为空"); return; } WEAKSELF SHOWLOADING NSString *modyUrl = [NSString stringWithFormat:@"%@%@",BaseUrl,UpdateUserInfoPUT]; [[HttpManager sharedHttpManager] PUTUrl:modyUrl parameters:@{@"description":self.editTextView.text} success:^(id _Nonnull responseObject) { [UserManager getUserInfoDetailSuccess:^(id _Nonnull responseObject) { REMOVESHOW STRONGSELF [strongSelf.navigationController popViewControllerAnimated:YES]; } failure:^(NSError * _Nonnull error) { REMOVESHOW SHOWERROR([ZYCTool handerResultData:error]) }]; NSLog(@"成功"); } failure:^(NSError * _Nonnull error) { REMOVESHOW NSLog(@"失败"); SHOWERROR([ZYCTool handerResultData:error]) }]; } - (void)commitData3{ WEAKSELF SHOWLOADING NSString *modyUrl = [NSString stringWithFormat:@"%@%@",BaseUrl,UpdateUserInfoPUT]; [[HttpManager sharedHttpManager] PUTUrl:modyUrl parameters:@{@"Nick":self.editTextView.text} success:^(id _Nonnull responseObject) { [UserManager getUserInfoDetailSuccess:^(id _Nonnull responseObject) { REMOVESHOW STRONGSELF [strongSelf.navigationController popViewControllerAnimated:YES]; } failure:^(NSError * _Nonnull error) { REMOVESHOW SHOWERROR([ZYCTool handerResultData:error]) }]; NSLog(@"成功"); } failure:^(NSError * _Nonnull error) { REMOVESHOW NSLog(@"失败"); SHOWERROR([ZYCTool handerResultData:error]) }]; } /****************************************************/ #pragma mark - UITextViewDelegate /****************************************************/ - (void)textViewDidEndEditing:(UITextView *)textView{ NSLog(@"%@",textView.text); } - (void)textViewDidChange:(UITextView *)textView { if (textView.text.length > 500) { textView.text = [textView.text substringToIndex:500]; } // self.textLengthLabel.text = [NSString stringWithFormat:@"%lu/500",(unsigned long)textView.text.length]; } - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{ NSString *tempString = [textView.text stringByReplacingCharactersInRange:range withString:text]; if (tempString.length > 500) { textView.text = [tempString substringToIndex:500]; return NO; } return YES; } /* #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