// // GiGaUserInfoVC.m // GIGA // // Created by lianxiang on 2018/9/19. // Copyright © 2018年 com.giga.ios. All rights reserved. // #import "GiGaUserInfoVC.h" #import "GiGaMineUserViewCell.h" #import "GiGAUserInfoCell.h" #import "UIImageView+WebCache.h" #import "GiGaUserViewController.h" #import "GIGaChangePassVC.h" #import "GiGaChangePhoneNumberVC.h" @interface GiGaUserInfoVC () @property (nonatomic,strong) GiGaUser *user; @end @implementation GiGaUserInfoVC - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self addNavTitile:@"个人中心"]; [self.view addSubview:self.tableView]; self.tableView.delegate = self; self.tableView.dataSource = self; self.tableView.backgroundColor = [UIColor whiteColor]; self.tableView.separatorStyle = UITableViewCellSelectionStyleNone; self.tableView.sectionFooterHeight = 0; self.tableView.estimatedSectionFooterHeight= 0; self.tableView.estimatedSectionHeaderHeight = 0; self.tableView.bounces = NO; self.tableView.frame = CGRectMake(0, 1, KMainW, self.view.bounds.size.height - SAFE_NAV_HEIGHT); GiGaUser *user = [[GiGaUserManager shareUser] getCurrentUser]; self.user = user; NC_ADD_TARGET_NAME_OBJECT(self, @selector(userAvatorUpDate), kUserAvatorUpdateNoti, nil); NC_ADD_TARGET_NAME_OBJECT(self, @selector(usersNameUpDateNoti), kUserNameUpDateNoti, nil); } -(void)dealloc{ NC_REMOVE_NAME(self, kUserAvatorUpdateNoti, nil); NC_REMOVE_NAME(self, kUserNameUpDateNoti, nil); } -(void)userAvatorUpDate{ GiGaUser *user = [[GiGaUserManager shareUser] getCurrentUser]; self.user = user; if (user.headImgUrl && ![user.headImgUrl isKindOfClass:[NSNull class]] ) { GiGaMineUserViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; NSURL *url = [NSURL URLWithString:user.headImgUrl]; [cell.userAvator sd_setImageWithURL:url]; } } -(void)usersNameUpDateNoti{ GiGaUser *user = [[GiGaUserManager shareUser] getCurrentUser]; self.user = user; if (user.nickName && ![user.nickName isEqualToString:@""] && ![user.nickName isKindOfClass:[NSNull class]]) { GiGaMineUserViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; cell.userName.text = user.nickName; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 2; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ if (section == 0){ return 1; } return 2; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ if(indexPath.section ==0){ GiGaMineUserViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GiGaMineUserViewCell"]; if(!cell){ cell = [[[NSBundle mainBundle] loadNibNamed:@"GiGaMineUserViewCell" owner:self options:nil] lastObject]; } if (self.user) { [cell loadUserinfoWith:self.user]; } return cell; } GiGAUserInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GiGAUserInfoCell"]; if(!cell){ cell = [[[NSBundle mainBundle] loadNibNamed:@"GiGAUserInfoCell" owner:self options:nil] lastObject]; } [cell loadCellData:indexPath]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ if(indexPath.section == 1){ [tableView deselectRowAtIndexPath:indexPath animated:YES]; } if(indexPath.section == 0){ GiGaUserViewController *userVC= [[GiGaUserViewController alloc] init]; [self.navigationController pushViewController:userVC animated:YES]; }else{ if (indexPath.section == 1 && indexPath.row == 0 ){ GiGaUserViewController *userVC= [[GiGaUserViewController alloc] init]; [self.navigationController pushViewController:userVC animated:YES]; }else{ GiGaChangePhoneNumberVC *changePass = [[GiGaChangePhoneNumberVC alloc] init]; [self.navigationController pushViewController:changePass animated:YES]; } } } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ if(indexPath.section==0){ return 139; }else { return 54; } } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return 0.1; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ if (section == 1){ return 6; } return 0.1; } -(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ if (section == 1) { UIView *view = [[UIView alloc] init]; view.backgroundColor = GIGARGB(222, 222, 222, 1); return view; } return nil; } @end