From 2665b5ad1fa9cf7dc8f6cfed861b97f82813d9e2 Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Thu, 4 Dec 2025 14:44:56 +0800 Subject: [PATCH] 2 --- keyBoard/Class/Me/V/KBMyHeaderView.m | 2 +- keyBoard/Class/Me/VC/KBPersonInfoVC.h | 1 - keyBoard/Class/Me/VC/KBPersonInfoVC.m | 40 ++++++++++++++++++--------- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/keyBoard/Class/Me/V/KBMyHeaderView.m b/keyBoard/Class/Me/V/KBMyHeaderView.m index 398cfd2..da8673d 100644 --- a/keyBoard/Class/Me/V/KBMyHeaderView.m +++ b/keyBoard/Class/Me/V/KBMyHeaderView.m @@ -227,7 +227,7 @@ } - (void)onAvatarTap { KBPersonInfoVC *vc = [[KBPersonInfoVC alloc] init]; - vc.userModel = self.userModel; +// vc.userModel = self.userModel; [KB_CURRENT_NAV pushViewController:vc animated:true]; } - (void)onLeftCardTap { diff --git a/keyBoard/Class/Me/VC/KBPersonInfoVC.h b/keyBoard/Class/Me/VC/KBPersonInfoVC.h index 96129bd..85db9b6 100644 --- a/keyBoard/Class/Me/VC/KBPersonInfoVC.h +++ b/keyBoard/Class/Me/VC/KBPersonInfoVC.h @@ -11,7 +11,6 @@ NS_ASSUME_NONNULL_BEGIN @interface KBPersonInfoVC : BaseViewController -@property (nonatomic, strong) KBUser *userModel; @end diff --git a/keyBoard/Class/Me/VC/KBPersonInfoVC.m b/keyBoard/Class/Me/VC/KBPersonInfoVC.m index 7d0eadb..884fb04 100644 --- a/keyBoard/Class/Me/VC/KBPersonInfoVC.m +++ b/keyBoard/Class/Me/VC/KBPersonInfoVC.m @@ -38,6 +38,8 @@ @property (nonatomic, strong) NSData *avatarJPEGData; @property (nonatomic, strong) KBMyVM *myVM; +@property (nonatomic, strong) KBMyVM *viewModel; // 我的页面 VM +@property (nonatomic, strong) KBUser *userModel; @end @@ -49,20 +51,13 @@ self.kb_navView.backgroundColor = [UIColor clearColor]; self.view.backgroundColor = [UIColor colorWithHex:0xF8F8F8]; - // 根据用户模型的 gender 显示当前性别,支持多语言 - NSString *genderText = [self kb_genderDisplayText]; - // 构造数据 // self.items = @[ // @{ @"title": KBLocalized(@"Nickname"), @"value": @"", @"arrow": @YES, @"copy": @NO }, // @{ @"title": KBLocalized(@"Gender"), @"value": @"Choose", @"arrow": @YES, @"copy": @NO }, // @{ @"title": KBLocalized(@"User ID"), @"value": @"", @"arrow": @NO, @"copy": @YES }, // ]; - self.items = @[ - @{ @"title": KBLocalized(@"Nickname"), @"value": self.userModel.nickName, @"arrow": @YES, @"copy": @NO }, - @{ @"title": KBLocalized(@"Gender"), @"value": genderText, @"arrow": @YES, @"copy": @NO }, - @{ @"title": KBLocalized(@"User ID"), @"value": self.userModel.userId, @"arrow": @NO, @"copy": @YES }, - ]; + [self.view addSubview:self.tableView]; [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { @@ -86,13 +81,25 @@ UIEdgeInsets inset = self.tableView.contentInset; inset.bottom = 56 + 24; // 按钮高度 + 额外间距 self.tableView.contentInset = inset; + self.viewModel = [[KBMyVM alloc] init]; + __weak typeof(self) weakSelf = self; + [self.viewModel fetchUserDetailWithCompletion:^(KBUser * _Nullable user, NSError * _Nullable error) { + if (user) { + weakSelf.userModel = user; + [weakSelf.avatarView kb_setAvatarURL:weakSelf.userModel.avatarUrl placeholder:KBPlaceholderImage]; + weakSelf.modifyLabel.text = weakSelf.userModel.nickName; + // 根据用户模型的 gender 显示当前性别,支持多语言 + NSString *genderText = [weakSelf kb_genderDisplayText]; + weakSelf.items = @[ + @{ @"title": KBLocalized(@"Nickname"), @"value": weakSelf.userModel.nickName, @"arrow": @YES, @"copy": @NO }, + @{ @"title": KBLocalized(@"Gender"), @"value": genderText, @"arrow": @YES, @"copy": @NO }, + @{ @"title": KBLocalized(@"User ID"), @"value": weakSelf.userModel.userId, @"arrow": @NO, @"copy": @YES }, + ]; + [weakSelf.tableView reloadData]; + } + }]; } -- (void)setUserModel:(KBUser *)userModel{ - _userModel = userModel; - [self.avatarView kb_setAvatarURL:userModel.avatarUrl placeholder:KBPlaceholderImage]; - self.modifyLabel.text = userModel.nickName; -} /// 根据 userModel.gender 生成展示用的性别文案(带多语言) - (NSString *)kb_genderDisplayText { @@ -162,6 +169,10 @@ content.closeHandler = ^{ [weakPop dismiss]; }; content.saveHandler = ^(NSString *nickname) { if (nickname.length > 0) { + // 更新本地模型,避免返回再进入还是旧数据 + weakSelf.userModel.nickName = nickname; + weakSelf.modifyLabel.text = nickname; + // 更新第一行展示 NSMutableArray *m = [weakSelf.items mutableCopy]; NSMutableDictionary *d0 = [m.firstObject mutableCopy]; @@ -214,6 +225,9 @@ [[NSUserDefaults standardUserDefaults] setInteger:genderValue forKey:KBSexSelectedGenderKey]; [[NSUserDefaults standardUserDefaults] synchronize]; + // 同步更新本地 userModel,避免再次进入页面还是旧的性别 + weakSelf.userModel.gender = (UserSex)genderValue; + NSMutableArray *m = [weakSelf.items mutableCopy]; NSMutableDictionary *d1 = [m[1] mutableCopy]; d1[@"value"] = name; m[1] = d1; weakSelf.items = m;