EditMySignOrBriefVC.m 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. //
  2. // EditMySignOrBriefVC.m
  3. // smartRhino
  4. //
  5. // Created by armin on 2019/11/1.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "EditMySignOrBriefVC.h"
  9. #import "UIPlaceHolderTextView.h"
  10. @interface EditMySignOrBriefVC ()<UITextViewDelegate>
  11. @property (strong,nonatomic) IBOutlet UILabel *pageTitleLabel;
  12. @property (strong,nonatomic) IBOutlet UIButton *okBtn;
  13. @property (strong,nonatomic) IBOutlet UIPlaceHolderTextView *editTextView;
  14. @end
  15. @implementation EditMySignOrBriefVC
  16. +(EditMySignOrBriefVC *)initEditMySignOrBriefVC{
  17. EditMySignOrBriefVC *controller = [StoryboardManager.shared.myCenter instantiateViewControllerWithIdentifier:@"EditMySignOrBriefVC"];
  18. return controller;
  19. }
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. self.fd_prefersNavigationBarHidden = YES;
  23. self.editTextView.delegate = self;
  24. if(self.pagetype == EditMySignOrBriefPageType1){
  25. self.pageTitleLabel.text = @"我的签名";
  26. self.editTextView.text = [AppUserModel sharedAppUserModel].Signature;
  27. if (self.editTextView.text.length == 0) {
  28. self.editTextView.placeholder = @"我的签名";
  29. }
  30. }else if(self.pagetype == EditMySignOrBriefPageType2){
  31. self.pageTitleLabel.text = @"自我介绍";
  32. self.editTextView.text = [AppUserModel sharedAppUserModel].Description;
  33. if (self.editTextView.text.length == 0) {
  34. self.editTextView.placeholder = @"自我介绍";
  35. }
  36. }else{
  37. self.pageTitleLabel.text = @"我的昵称";
  38. self.editTextView.text = [AppUserModel sharedAppUserModel].Nick;
  39. if (self.editTextView.text.length == 0) {
  40. self.editTextView.placeholder = @"我的昵称";
  41. }
  42. }
  43. NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
  44. paragraphStyle.lineSpacing = 12;// 字体的行间距
  45. NSDictionary *attributes = @{
  46. NSFontAttributeName:[UIFont systemFontOfSize:16],
  47. NSParagraphStyleAttributeName:paragraphStyle
  48. };
  49. self.editTextView.typingAttributes = attributes;
  50. WEAKSELF
  51. [self.okBtn setAction:^{
  52. STRONGSELF
  53. if(strongSelf.pagetype == EditMySignOrBriefPageType1){
  54. [strongSelf commitData];
  55. }else if(strongSelf.pagetype == EditMySignOrBriefPageType2){
  56. [strongSelf commitData2];
  57. }else{
  58. [strongSelf commitData3];
  59. }
  60. }];
  61. }
  62. - (void)commitData{
  63. WEAKSELF
  64. SHOWLOADING
  65. NSString *modyUrl = [NSString stringWithFormat:@"%@%@",BaseUrl,UpdateUserInfoPUT];
  66. [[HttpManager sharedHttpManager] PUTUrl:modyUrl parameters:@{@"signature":self.editTextView.text} success:^(id _Nonnull responseObject) {
  67. [UserManager getUserInfoDetailSuccess:^(id _Nonnull responseObject) {
  68. REMOVESHOW
  69. STRONGSELF
  70. [strongSelf.navigationController popViewControllerAnimated:YES];
  71. } failure:^(NSError * _Nonnull error) {
  72. REMOVESHOW
  73. SHOWERROR([ZYCTool handerResultData:error])
  74. }];
  75. NSLog(@"成功");
  76. } failure:^(NSError * _Nonnull error) {
  77. REMOVESHOW
  78. NSLog(@"失败");
  79. SHOWERROR([ZYCTool handerResultData:error])
  80. }];
  81. }
  82. - (void)commitData2{
  83. if (self.editTextView.text.length == 0) {
  84. SHOWERROR(@"内容不能为空");
  85. return;
  86. }
  87. WEAKSELF
  88. SHOWLOADING
  89. NSString *modyUrl = [NSString stringWithFormat:@"%@%@",BaseUrl,UpdateUserInfoPUT];
  90. [[HttpManager sharedHttpManager] PUTUrl:modyUrl parameters:@{@"description":self.editTextView.text} success:^(id _Nonnull responseObject) {
  91. [UserManager getUserInfoDetailSuccess:^(id _Nonnull responseObject) {
  92. REMOVESHOW
  93. STRONGSELF
  94. [strongSelf.navigationController popViewControllerAnimated:YES];
  95. } failure:^(NSError * _Nonnull error) {
  96. REMOVESHOW
  97. SHOWERROR([ZYCTool handerResultData:error])
  98. }];
  99. NSLog(@"成功");
  100. } failure:^(NSError * _Nonnull error) {
  101. REMOVESHOW
  102. NSLog(@"失败");
  103. SHOWERROR([ZYCTool handerResultData:error])
  104. }];
  105. }
  106. - (void)commitData3{
  107. WEAKSELF
  108. SHOWLOADING
  109. NSString *modyUrl = [NSString stringWithFormat:@"%@%@",BaseUrl,UpdateUserInfoPUT];
  110. [[HttpManager sharedHttpManager] PUTUrl:modyUrl parameters:@{@"Nick":self.editTextView.text} success:^(id _Nonnull responseObject) {
  111. [UserManager getUserInfoDetailSuccess:^(id _Nonnull responseObject) {
  112. REMOVESHOW
  113. STRONGSELF
  114. [strongSelf.navigationController popViewControllerAnimated:YES];
  115. } failure:^(NSError * _Nonnull error) {
  116. REMOVESHOW
  117. SHOWERROR([ZYCTool handerResultData:error])
  118. }];
  119. NSLog(@"成功");
  120. } failure:^(NSError * _Nonnull error) {
  121. REMOVESHOW
  122. NSLog(@"失败");
  123. SHOWERROR([ZYCTool handerResultData:error])
  124. }];
  125. }
  126. /****************************************************/
  127. #pragma mark - UITextViewDelegate
  128. /****************************************************/
  129. - (void)textViewDidEndEditing:(UITextView *)textView{
  130. NSLog(@"%@",textView.text);
  131. }
  132. - (void)textViewDidChange:(UITextView *)textView
  133. {
  134. if (textView.text.length > 500) {
  135. textView.text = [textView.text substringToIndex:500];
  136. }
  137. // self.textLengthLabel.text = [NSString stringWithFormat:@"%lu/500",(unsigned long)textView.text.length];
  138. }
  139. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
  140. NSString *tempString = [textView.text stringByReplacingCharactersInRange:range withString:text];
  141. if (tempString.length > 500) {
  142. textView.text = [tempString substringToIndex:500];
  143. return NO;
  144. }
  145. return YES;
  146. }
  147. /*
  148. #pragma mark - Navigation
  149. // In a storyboard-based application, you will often want to do a little preparation before navigation
  150. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  151. // Get the new view controller using [segue destinationViewController].
  152. // Pass the selected object to the new view controller.
  153. }
  154. */
  155. @end