FirstSettingViewController.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // FirstSettingViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/20.
  6. //
  7. #import "FirstSettingViewController.h"
  8. #import "FirstSettingBodyView.h"
  9. #import "AppDelegate.h"
  10. #import "UserInfoManager.h"
  11. @interface FirstSettingViewController ()
  12. @property (nonatomic, strong) FirstSettingBodyView *bodyView;
  13. @property (nonatomic, strong) NSString *userSex;
  14. @end
  15. @implementation FirstSettingViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. // Do any additional setup after loading the view.
  19. self.ks_prefersNavigationBarHidden = YES;
  20. [self configUI];
  21. }
  22. - (void)configUI {
  23. CGFloat height = KPortraitHeight;
  24. _bodyView = [FirstSettingBodyView shareInstance];
  25. [self.scrollView addSubview:_bodyView];
  26. [_bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
  27. make.top.mas_equalTo(self.scrollView.mas_top);
  28. make.right.left.mas_equalTo(self.view);
  29. make.height.mas_equalTo(height);
  30. }];
  31. MJWeakSelf;
  32. [_bodyView sureCallback:^(NSString *myCode, NSString *nickName) {
  33. [weakSelf settingPassword:myCode nickName:nickName];
  34. }];
  35. [_bodyView chooseSexCallback:^{
  36. [weakSelf showModifySexAlert];
  37. }];
  38. }
  39. - (void)showModifySexAlert {
  40. NSString *titleString = @"选择性别";
  41. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"" message:titleString preferredStyle:IS_IPAD ? UIAlertControllerStyleAlert : UIAlertControllerStyleActionSheet];
  42. NSMutableAttributedString *titleAtt = [[NSMutableAttributedString alloc] initWithString:titleString];
  43. [titleAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16.0f] range:NSMakeRange(0, titleString.length)];
  44. [titleAtt addAttribute:NSForegroundColorAttributeName value:HexRGB(0x999999) range:NSMakeRange(0, titleString.length)];
  45. [alertVC setValue:titleAtt forKey:@"attributedMessage"];
  46. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"男" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  47. self.bodyView.sexField.text = @"男";
  48. self.userSex = @"1";
  49. }];
  50. [actionOne setValue:THEMECOLOR forKey:@"_titleTextColor"];
  51. [alertVC addAction:actionOne];
  52. UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"女" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  53. self.bodyView.sexField.text = @"女";
  54. self.userSex = @"0";
  55. }];
  56. [actionTwo setValue:THEMECOLOR forKey:@"_titleTextColor"];
  57. [alertVC addAction:actionTwo];
  58. UIAlertAction *cancleAlert = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  59. }];
  60. [alertVC addAction:cancleAlert];
  61. [cancleAlert setValue:HexRGB(0x444444) forKey:@"_titleTextColor"];
  62. alertVC.modalPresentationStyle = UIModalPresentationFullScreen;
  63. [self presentViewController:alertVC animated:true completion:nil];
  64. }
  65. - (void)settingPassword:(NSString *)pwdCode nickName:(NSString *)nickName {
  66. if ([NSString isEmptyString:self.userSex]) {
  67. [self MBPShow:@"请设置性别"];
  68. return;
  69. }
  70. [self showhud];
  71. [KSNetworkingManager setPasswordRequest:KS_POST username:nickName password:pwdCode userSex:self.userSex token:self.access_token success:^(NSDictionary * _Nonnull dic) {
  72. [self removehub];
  73. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  74. MJWeakSelf;
  75. UserDefaultSet(self.phone, PHONEKEY);
  76. UserDefaultSet(self.access_token, TokenKey);
  77. UserDefaultSet(pwdCode, PASSWORDKEY);
  78. [self KSShowMsg:@"设置成功" promptCompletion:^{
  79. [weakSelf toHomeView];
  80. }];
  81. }
  82. else {
  83. [self MBPShow:MESSAGEKEY];
  84. }
  85. } faliure:^(NSError * _Nonnull error) {
  86. [self removehub];
  87. }];
  88. }
  89. - (void)toHomeView {
  90. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  91. [appDelegate initTableBar];
  92. UITabBarController *tabBarController = appDelegate.tabBarController;
  93. [tabBarController setSelectedIndex:0];
  94. appDelegate.window.rootViewController = tabBarController;
  95. }
  96. /*
  97. #pragma mark - Navigation
  98. // In a storyboard-based application, you will often want to do a little preparation before navigation
  99. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  100. // Get the new view controller using [segue destinationViewController].
  101. // Pass the selected object to the new view controller.
  102. }
  103. */
  104. @end