YOUPAILZUpdateSignVC.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // YOUPAILZUpdateSignVC.m
  3. // MEISHI
  4. //
  5. // Created by CY on 2021/1/12.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAILZUpdateSignVC.h"
  9. #import "YOUPAILZTextView.h"
  10. @interface YOUPAILZUpdateSignVC ()
  11. @property(nonatomic,strong)YOUPAILZTextView *youpaiptextView;
  12. @end
  13. @implementation YOUPAILZUpdateSignVC
  14. - (void)viewWillDisappear:(BOOL)animated{
  15. [super viewWillDisappear:animated];
  16. // self.sx_disableInteractivePop = NO;
  17. }
  18. - (void)viewDidAppear:(BOOL)animated{
  19. [super viewDidAppear:animated];
  20. [self.youpaiptextView.youpaiptextView becomeFirstResponder];
  21. self.sx_disableInteractivePop = YES;
  22. }
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. [self youpaifsetupView];
  26. self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(youpaifbackNeedSave) image:[UIImage imageNamed:@"vqu_images_navigation_back_black"]];
  27. }
  28. - (void)youpaifbackNeedSave{
  29. if ([self.youpaiptextView.youpaiptextView.text isEqualToString:self.youpaipsign] && (![self.youpaiptextView.youpaiptextView.text isEqualToString:@""])) {
  30. [self.navigationController popViewControllerAnimated:YES];
  31. }else{
  32. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"保存信息" message:@"是否保存本次修改内容?" preferredStyle:UIAlertControllerStyleAlert];
  33. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"不保存" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
  34. [self.navigationController popViewControllerAnimated:YES];
  35. }];
  36. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"保存" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
  37. [self youpaifSaveRemark];
  38. }];
  39. [alertController addAction:cancelAction];
  40. [alertController addAction:okAction];
  41. [self presentViewController:alertController animated:YES completion:nil];
  42. }
  43. }
  44. - (void)youpaifsetupView{
  45. //设置导航栏
  46. self.title = @"个人介绍";
  47. self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(youpaifSaveRemark) title:@"保存" font:LCFont15 titleColor:LZA3AABEColor highlightedColor:LZA3AABEColor titleEdgeInsets:UIEdgeInsetsZero];
  48. self.navigationItem.rightBarButtonItem.enabled = NO;
  49. //设置textView
  50. UIScrollView* scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, NavBarHeight, KScreenWidth, KScreenHeight-NavBarHeight)];
  51. scrollView.contentSize = CGSizeMake(KScreenWidth, KScreenHeight-NavBarHeight+1);
  52. scrollView.bounces = YES;
  53. scrollView.showsHorizontalScrollIndicator = NO;
  54. scrollView.showsVerticalScrollIndicator = NO;
  55. [self.view addSubview:scrollView];
  56. self.view.backgroundColor = [UIColor whiteColor];
  57. YOUPAILZTextView *textView = [[YOUPAILZTextView alloc] initWithMaxCount:100];
  58. textView.frame = CGRectMake(14, 25, KScreenWidth-28, 139);
  59. textView.youpaiptextViewPadding = UIEdgeInsetsMake(14.0f, 14.0f, 10.0f, 14.0f);
  60. textView.youpaiptextLengthDefaultColor = LZD3D1D7Color;
  61. textView.youpaiptextLengthHigtColor = LZ7C69FEColor;
  62. textView.youpaiptextLengthFont = LCFont(14.0f);
  63. textView.youpaiptextLengthRight = 14.0f;
  64. textView.youpaiptextLengthBottom = 14.0f;
  65. textView.youpaiptextView.placeholderFont = LCFont(14.0f);
  66. textView.youpaiptextView.placeholderTextColor = LZF7F8FAColor;
  67. textView.youpaiptextView.placeholderText = @"简单介绍一下自己吧…";
  68. textView.youpaiptextView.font = LCFont(14.0f);
  69. textView.layer.cornerRadius = 5.0f;
  70. textView.clipsToBounds = YES;
  71. textView.tintColor = LZ7C69FEColor;
  72. [scrollView addSubview:textView];
  73. textView.youpaiptextView.textColor = LZ273145Color;
  74. self.youpaiptextView = textView;
  75. textView.backgroundColor = LZF7F8FAColor;
  76. textView.youpaiptextView.text = self.youpaipsign;
  77. [RACObserve(textView.youpaiptextView, text) subscribeNext:^(id _Nullable x) {
  78. if ([x isEqualToString:self.youpaipsign]) {
  79. self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(youpaifSaveRemark) title:@"保存" font:LCFont15 titleColor:LZA3AABEColor highlightedColor:LZA3AABEColor titleEdgeInsets:UIEdgeInsetsZero];
  80. self.navigationItem.rightBarButtonItem.enabled = NO;
  81. }else{
  82. self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(youpaifSaveRemark) title:@"保存" font:LCFont15 titleColor:LZ7C69FEColor highlightedColor:LZ7C69FEColor titleEdgeInsets:UIEdgeInsetsZero];
  83. self.navigationItem.rightBarButtonItem.enabled = YES;
  84. }
  85. }];
  86. }
  87. ////在这个地方计算输入的字数
  88. //- (void)textViewDidChange:(UITextView *)textView{
  89. //
  90. // if ([textView.text isEqualToString:self.youpaipsign]) {
  91. // self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(youpaifSaveRemark) title:@"保存" font:LCFont15 titleColor:HexColorFromRGB(0x9F9DA5) highlightedColor:HexColorFromRGB(0x9F9DA5) titleEdgeInsets:UIEdgeInsetsZero];
  92. // self.navigationItem.rightBarButtonItem.enabled = NO;
  93. // }else{
  94. // self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(youpaifSaveRemark) title:@"保存" font:LCFont15 titleColor:ZYPinkColor highlightedColor:ZYPinkColor titleEdgeInsets:UIEdgeInsetsZero];
  95. // self.navigationItem.rightBarButtonItem.enabled = YES;
  96. //
  97. // }
  98. //}
  99. - (void)youpaifSaveRemark{
  100. //加一个正则判断昵称是否符合规则 正则限制/[\x{4e00}-\x{9fa5}\w]+$/u 长度限制2~12个utf8字符
  101. // if (self.textField.text.length<1 || self.textField.text.length>10) {
  102. // [ZCHUDHelper showTitle:@"昵称长度为1~10个字符"];
  103. // }else{
  104. [LCHttpHelper requestWithURLString:UpdateUserMsg parameters:@{@"signature":self.youpaiptextView.youpaiptextView.text}
  105. needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  106. NSDictionary* dict = (NSDictionary*)responseObject;
  107. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  108. if (code==0) {//成功
  109. YOUPAILCUserModel* userModel = [LCSaveModel getUserModel];
  110. userModel.youpaipuserinfo.youpaipsign = self.youpaiptextView.youpaiptextView.text;
  111. [LCSaveModel saveUserModel:userModel];
  112. if (self.youpaipblock) {
  113. self.youpaipblock(self.youpaiptextView.youpaiptextView.text);
  114. }
  115. [self.navigationController popViewControllerAnimated:YES];
  116. }
  117. } failure:^(NSError *error) {
  118. }];
  119. // }
  120. }
  121. @end