YOUPAILCUpdateRecomIdVC.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // YOUPAILCUpdateRecomIdVC.m
  3. // LiveChat
  4. //
  5. // Created by 张灿 on 2018/4/14.
  6. // Copyright © 2018年 caicai. All rights reserved.
  7. //
  8. #import "YOUPAILCUpdateRecomIdVC.h"
  9. @interface YOUPAILCUpdateRecomIdVC ()<UITextFieldDelegate>
  10. @property(nonatomic,strong)UITextField* youpaiptextField;
  11. @end
  12. @implementation YOUPAILCUpdateRecomIdVC
  13. - (void)viewWillDisappear:(BOOL)animated{
  14. [super viewWillDisappear:animated];
  15. // self.sx_disableInteractivePop = NO;
  16. }
  17. - (void)viewDidAppear:(BOOL)animated{
  18. [super viewDidAppear:animated];
  19. [self.youpaiptextField becomeFirstResponder];
  20. self.sx_disableInteractivePop = YES;
  21. }
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. self.title = @"推荐人花舞号";
  25. [self youpaifsetupView];
  26. self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(youpaifbackNeedSave) image:[UIImage imageNamed:@"nav_back_normal"]];
  27. }
  28. - (void)youpaifbackNeedSave{
  29. if ([self.youpaiptextField.text isEqualToString:self.youpaiprecomId] && (![self.youpaiptextField.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. self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(SaveRemark) title:@"保存" font:LCFont12 titleColor:LCGray highlightedColor:LCGray titleEdgeInsets:UIEdgeInsetsZero];
  46. self.navigationItem.rightBarButtonItem.enabled = NO;
  47. //设置textView
  48. UIScrollView* scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, NavBarHeight, KScreenWidth, KScreenHeight-NavBarHeight)];
  49. scrollView.contentSize = CGSizeMake(KScreenWidth, KScreenHeight-NavBarHeight+1);
  50. scrollView.bounces = YES;
  51. scrollView.showsHorizontalScrollIndicator = NO;
  52. scrollView.showsVerticalScrollIndicator = NO;
  53. [self.view addSubview:scrollView];
  54. UITextField* textField = [[UITextField alloc]initWithFrame:CGRectMake(16,30, KScreenWidth-32, 45)];
  55. textField.backgroundColor = [UIColor whiteColor];
  56. textField.layer.cornerRadius = 8;
  57. textField.layer.masksToBounds = YES;
  58. textField.delegate = self;
  59. textField.text = self.youpaiprecomId;
  60. textField.font = [UIFont systemFontOfSize:12];
  61. textField.textColor = HexColorFromRGB(0x333333);
  62. textField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 19, 45)];
  63. textField.leftViewMode = UITextFieldViewModeAlways;
  64. textField.clearButtonMode = UITextFieldViewModeAlways;
  65. [[textField valueForKey:@"_clearButton"] setImage:[UIImage imageNamed:@"vqu_images_D_nick_clean"] forState:UIControlStateNormal];
  66. textField.placeholder = @"输入推荐人花舞号";
  67. textField.keyboardType = UIKeyboardTypeNumberPad;
  68. self.youpaiptextField = textField;
  69. [scrollView addSubview:textField];
  70. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaiftextDidChange) name:UITextFieldTextDidChangeNotification object:textField];
  71. }
  72. - (void)youpaiftextDidChange{
  73. NSLog(@"%@",self.youpaiptextField.text);
  74. if ([self.youpaiptextField.text isEqualToString:self.youpaiprecomId]) {
  75. self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(youpaifSaveRemark) title:@"保存" font:LCFont12 titleColor:LCGray highlightedColor:LCGray titleEdgeInsets:UIEdgeInsetsZero];
  76. self.navigationItem.rightBarButtonItem.enabled = NO;
  77. }else{
  78. self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(youpaifSaveRemark) title:@"保存" font:LCFont12 titleColor:ZYPinkColor highlightedColor:ZYPinkColor titleEdgeInsets:UIEdgeInsetsZero];
  79. self.navigationItem.rightBarButtonItem.enabled = YES;
  80. }
  81. if(self.youpaiptextField.text.length>11){
  82. self.youpaiptextField.text = [self.youpaiptextField.text substringToIndex:11];
  83. }
  84. }
  85. - (void)youpaifSaveRemark{
  86. if (self.youpaipblock) {
  87. self.youpaipblock(self.youpaiptextField.text);
  88. }
  89. [self.navigationController popViewControllerAnimated:YES];
  90. }
  91. - (void)dealloc
  92. {
  93. [[NSNotificationCenter defaultCenter]removeObserver:self name:UITextViewTextDidChangeNotification object:self.youpaiptextField];
  94. }
  95. @end