2
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user