WFCUModifyMyProfileViewController.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // ModifyMyProfileViewController.m
  3. // WildFireChat
  4. //
  5. // Created by heavyrain.lee on 2018/5/20.
  6. // Copyright © 2018 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUModifyMyProfileViewController.h"
  9. #import "MBProgressHUD.h"
  10. #import <WFChatClient/WFCChatClient.h>
  11. @interface WFCUModifyMyProfileViewController () <UITextFieldDelegate, UITextInputDelegate>
  12. @property(nonatomic, strong)UITextField *textField;
  13. @end
  14. @implementation WFCUModifyMyProfileViewController
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:[WFCCNetworkService sharedInstance].userId refresh:NO];
  18. NSString *title = nil;
  19. NSString *defaultValue = nil;
  20. switch (self.modifyType) {
  21. case Modify_Email:
  22. title = @"修改邮箱";
  23. defaultValue = userInfo.email;
  24. self.textField.keyboardType = UIKeyboardTypeEmailAddress;
  25. break;
  26. case Modify_Mobile:
  27. title = @"修改电话";
  28. defaultValue = userInfo.mobile;
  29. self.textField.keyboardType = UIKeyboardTypePhonePad;
  30. break;
  31. case Modify_Social:
  32. title = @"修改社交账号";
  33. defaultValue = userInfo.social;
  34. break;
  35. case Modify_Address:
  36. title = @"修改地址";
  37. defaultValue = userInfo.address;
  38. break;
  39. case Modify_Company:
  40. title = @"修改公司信息";
  41. defaultValue = userInfo.company;
  42. break;
  43. case Modify_DisplayName:
  44. title = @"修改昵称";
  45. defaultValue = userInfo.displayName;
  46. break;
  47. default:
  48. break;
  49. }
  50. self.textField.text = defaultValue;
  51. [self setTitle:title];
  52. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"确定" style:UIBarButtonItemStyleDone target:self action:@selector(onDone:)];
  53. [self.view setBackgroundColor:[UIColor colorWithRed:232/255.f green:232/255.f blue:232/255.f alpha:1.f]];
  54. [self.textField becomeFirstResponder];
  55. }
  56. - (void)onDone:(id)sender {
  57. [self.textField resignFirstResponder];
  58. __weak typeof(self) ws = self;
  59. __block MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  60. hud.label.text = @"修改中...";
  61. [hud showAnimated:YES];
  62. [[WFCCIMService sharedWFCIMService] modifyMyInfo:@{@(self.modifyType):self.textField.text} success:^{
  63. [hud hideAnimated:NO];
  64. self.onModified(self.modifyType, self.textField.text);
  65. [ws.navigationController popViewControllerAnimated:YES];
  66. } error:^(int error_code) {
  67. [hud hideAnimated:NO];
  68. hud = [MBProgressHUD showHUDAddedTo:ws.view animated:YES];
  69. hud.mode = MBProgressHUDModeText;
  70. hud.label.text = @"修改失败";
  71. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  72. [hud hideAnimated:YES afterDelay:1.f];
  73. }];
  74. }
  75. - (void)didReceiveMemoryWarning {
  76. [super didReceiveMemoryWarning];
  77. // Dispose of any resources that can be recreated.
  78. }
  79. - (UITextField *)textField {
  80. if(!_textField) {
  81. _textField = [[UITextField alloc] initWithFrame:CGRectMake(0, kStatusBarAndNavigationBarHeight + 20, [UIScreen mainScreen].bounds.size.width, 32)];
  82. _textField.borderStyle = UITextBorderStyleRoundedRect;
  83. _textField.clearButtonMode = UITextFieldViewModeAlways;
  84. _textField.delegate = self;
  85. _textField.inputDelegate = self;
  86. [self.view addSubview:_textField];
  87. }
  88. return _textField;
  89. }
  90. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  91. [self onDone:textField];
  92. return YES;
  93. }
  94. #pragma mark - UITextInputDelegate
  95. - (void)textDidChange:(nullable id <UITextInput>)textInput {
  96. if (self.textField.text.length) {
  97. self.navigationItem.rightBarButtonItem.enabled = YES;
  98. } else {
  99. self.navigationItem.rightBarButtonItem.enabled = NO;
  100. }
  101. }
  102. @end