SettingsNameSetViewController.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // SettingsNameSetViewController.m
  3. // OneCable
  4. //
  5. // Created by nComz on 2017. 4. 19..
  6. // Copyright © 2017년 ntels. All rights reserved.
  7. //
  8. #import "SettingsNameSetViewController.h"
  9. #import "CustomLabel.h"
  10. #import "CustomButton.h"
  11. #import "CustomTextField.h"
  12. #import "JDObject.h"
  13. #import "RequestHandler.h"
  14. #import "JDJSONModel.h"
  15. #import "ValidateUtil.h"
  16. @interface SettingsNameSetViewController () <CustomTextFieldDelegate>
  17. @end
  18. @implementation SettingsNameSetViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. [self initUI];
  22. }
  23. - (void)initUI {
  24. UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
  25. statusBar.backgroundColor = [UIColor whiteColor];
  26. _txtInputName.placeholder = [[JDFacade facade].loginUser.nickname isEqualToString:@""]? @"" :[JDFacade facade].loginUser.nickname;
  27. _txtInputName.returnKeyType = UIReturnKeyDone;
  28. _txtInputName.delegate = self;
  29. [self.navigationController.navigationBar setHidden:YES];
  30. self.navigationController.interactivePopGestureRecognizer.enabled = NO;
  31. }
  32. - (void)requestChangeNickname {
  33. //parameters
  34. NSDictionary *parameter = @{@"type": @"nickname" ,
  35. @"nickname": _txtInputName.text};
  36. // NSString *path = [NSString stringWithFormat:API_PUT_MEMBER_UPDATE, [JDFacade facade].loginUser.memberId, @"name"];
  37. NSString *path = [[JDFacade facade] getUrlWithCustGroupIDAndMemberID:API_PUT_MEMBER_UPDATE];
  38. [[RequestHandler handler] sendAsyncPutRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  39. // if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  40. // return;
  41. // }
  42. // JDJSONModel *result = (JDJSONModel *) responseObject;
  43. // if (result) {//API 성공 ,
  44. // [[JDFacade facade] toast:NSLocalizedString(@"이름이 변경되었습니다", nil)];
  45. [JDFacade facade].loginUser.nickname = _txtInputName.text;
  46. [[self navigationController] popToRootViewControllerAnimated:YES];
  47. // [super btnConfirmTouched:nil];
  48. // }
  49. } failure:^(id errorObject) {
  50. JDErrorModel *error = (JDErrorModel *)errorObject;
  51. [[JDFacade facade] alert:error.errorMessage];
  52. }];
  53. }
  54. - (IBAction)btnSaveTouched:(id)sender {
  55. // if (_txtInputName.text.trim.length != 0 && ![ValidateUtil validateTextfiled:_txtInputName
  56. // type:ValidateTypeNickname
  57. // title:NSLocalizedString(@"이름", @"이름")])
  58. // return;
  59. [self requestChangeNickname];
  60. }
  61. - (IBAction)btnCancelTouched:(id)sender {
  62. // [self dismissViewControllerAnimated:YES completion:nil];
  63. [[self navigationController] popToRootViewControllerAnimated:YES];
  64. }
  65. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  66. if ([textField isEqual:_txtInputName]) {
  67. [textField resignFirstResponder];
  68. }
  69. return YES;
  70. }
  71. - (void)didReceiveMemoryWarning {
  72. [super didReceiveMemoryWarning];
  73. }
  74. @end