热更新demo

userInfoTableController.m 14KB

    // // userInfoTableController.m // ThePaperBase // // Created by Huixin on 15/8/27. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "userInfoTableController.h" #import "shareUtil.h" #import "userInfoBaseCell.h" #import "userInfoSexCell.h" #import "userInfoTextCell.h" #import "userInfoThirdAccountCell.h" #import "bindThirdAccountController.h" #import "editSnameController.h" #import "editMobileController.h" #import "editMailController.h" #import "modifyPwdController.h" #import "modifyAreaController.h" #import "editSignController.h" #import "modifyAddressController.h" @interface userInfoTableController () <UIAlertViewDelegate> @property(nonatomic, strong)userBO *userBO; @property(nonatomic, strong)NSMutableArray *dataList; @property(nonatomic, strong)UITableViewCell *spaceCell; @end @implementation userInfoTableController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode) name:REFRESHAFTERNIGHTMODE object:nil]; [self configCanRefresh:NO canLoad:NO]; self.view.backgroundColor = [UIColor clearColor]; self.tableView.backgroundColor = [UIColor clearColor]; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.showsVerticalScrollIndicator = NO; self.tableView.clipsToBounds = YES; self.tableView.bounces = NO; for (id obj in self.tableView.subviews) { if ([obj respondsToSelector:@selector(setDelaysContentTouches:)]) { [obj setDelaysContentTouches:NO]; } } if (!IS_IPHONE_6P) { self.tableView.scrollEnabled = YES; }else { self.tableView.scrollEnabled = NO; } [self layoutViews]; } - (void)needrefreshNightMode { _spaceCell.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; //bug5238: 个人信息页点击效果的颜色 } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.userBO = [TPUserDefault instance].userBO; } - (void)layoutViews { [self.tableView makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.view); }]; } #pragma mark - get and set method - (void)setUserBO:(userBO *)user { _userBO = user; [self buildDataList:user]; [self.tableView reloadData]; } - (void)buildDataList:(userBO*)userBO { self.dataList = [NSMutableArray array]; [self.dataList addObject:@""]; [self.dataList addObject:userBO.sname?userBO.sname:@""]; [self.dataList addObject:userBO.sex?userBO.sex:@""]; [self.dataList addObject:userBO.mobile?userBO.mobile:@""]; [self.dataList addObject:userBO.mail?userBO.mail:@""]; [self.dataList addObject:userBO.address?userBO.address:@""]; [self.dataList addObject:userBO.loginType?userBO.loginType:@""]; [self.dataList addObject:@""]; [self.dataList addObject:userBO.area?userBO.area:@""]; [self.dataList addObject:userBO.perDesc?userBO.perDesc:@""]; [self.dataList addObject:@""]; } #pragma mark - btn event handler - (void)loginOut:(UIButton*)btn { UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"是否退出登录?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil]; [alert show]; } - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex != 0) { [Remote doJsonAction:0 requestUrl:loginOutURL parameter:nil delegate:self]; } } #pragma mark - UITableViewDelegate and UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataList.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 0) { return 10; }else if (indexPath.row == 10) { return 60; }else { return 100/2+0.5; } } - (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 0) { return [self returnSpaceCell:table cellForRowAtIndexPath:indexPath]; }else if (indexPath.row == 2){ return [self returnSexCell:table cellForRowAtIndexPath:indexPath]; }else if (indexPath.row == 6) { return [self returnThirdAccountCell:table cellForRowAtIndexPath:indexPath]; }else if (indexPath.row == 7) { return [self returnDefaultCell:table cellForRowAtIndexPath:indexPath]; }else if (indexPath.row == 10) { return [self returnOutLoginCell:table cellForRowAtIndexPath:indexPath]; }else { return [self returnTextCell:table cellForRowAtIndexPath:indexPath]; } } - (UITableViewCell*)returnSpaceCell:(UITableView*)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString* spaceCellId = @"spaceCellId"; _spaceCell = [table dequeueReusableCellWithIdentifier:spaceCellId]; if (nil == _spaceCell) { _spaceCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:spaceCellId]; _spaceCell.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; //bug5238: 个人信息页点击效果的颜色 _spaceCell.selectionStyle = UITableViewCellSelectionStyleNone; } return _spaceCell; } - (UITableViewCell*)returnSexCell:(UITableView*)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString* sexCell = @"sexCell"; userInfoSexCell* cell = (userInfoSexCell*)[table dequeueReusableCellWithIdentifier:sexCell]; if (nil == cell) { cell = [[userInfoSexCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sexCell]; } cell.title = @"性别"; if (self.dataList.count > 0) { NSString *sexStr = self.dataList[indexPath.row]; cell.sex = sexStr; } return cell; } - (UITableViewCell*)returnThirdAccountCell:(UITableView*)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString* thirdAccountCell = @"thirdAccountCell"; userInfoThirdAccountCell* cell = (userInfoThirdAccountCell*)[table dequeueReusableCellWithIdentifier:thirdAccountCell]; if (nil == cell) { cell = [[userInfoThirdAccountCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:thirdAccountCell]; } cell.title = @"社交账号绑定"; if (self.dataList.count > 0) { NSString *loginStr = self.dataList[indexPath.row]; cell.loginType = loginStr; } return cell; } - (UITableViewCell*)returnDefaultCell:(UITableView*)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString* defaultCell = @"defaultCell"; userInfoBaseCell* cell = (userInfoBaseCell*)[table dequeueReusableCellWithIdentifier:defaultCell]; if (nil == cell) { cell = [[userInfoBaseCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:defaultCell]; } if (indexPath.row == 7) { cell.title = @"修改密码"; } return cell; } - (UITableViewCell*)returnTextCell:(UITableView*)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString* textCell = @"userInfoTextCell"; userInfoTextCell* cell = (userInfoTextCell*)[table dequeueReusableCellWithIdentifier:textCell]; if (nil == cell) { cell = [[userInfoTextCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:textCell]; } if (indexPath.row == 1) { if ([_userBO.isAuth integerValue] == 1) { cell.title = @"真实姓名"; [cell configCanSelected:NO]; } else cell.title = @"昵称"; }else if (indexPath.row == 3) { cell.title = @"手机"; }else if (indexPath.row == 4) { cell.title = @"邮箱"; }else if (indexPath.row == 5) { cell.title = @"地址"; }else if (indexPath.row == 8) { cell.title = @"地区"; }else if (indexPath.row == 9) { if ([_userBO.isAuth integerValue] == 1) { cell.title = @"认证说明"; [cell configCanSelected:NO]; } else cell.title = @"签名"; } if (self.dataList.count > 0) { NSString *infoText = self.dataList[indexPath.row]; if (indexPath.row == 5) { infoText = [infoText stringByReplacingOccurrencesOfString:@"\n" withString:@" "]; } cell.infoText = infoText; } return cell; } - (UITableViewCell *)returnOutLoginCell:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString* outLoginCellId = @"outLoginCellId"; UITableViewCell* cell = [table dequeueReusableCellWithIdentifier:outLoginCellId]; if (nil == cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:outLoginCellId]; cell.backgroundColor = [UIColor clearColor]; cell.selectionStyle = UITableViewCellSelectionStyleNone; for (id obj in cell.subviews) { if ([obj respondsToSelector:@selector(setDelaysContentTouches:)]) { [obj setDelaysContentTouches:NO]; } } TPCustomButton *button = [[TPCustomButton alloc]init]; button.title = @"退出登录"; button.tag = 100; [button addTarget:self action:@selector(loginOut:) forControlEvents:UIControlEventTouchUpInside]; [cell addSubview:button]; [button makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(cell.top).offset(10); make.left.equalTo(cell.left).offset(10); make.right.equalTo(cell.right).offset(-10); make.height.mas_equalTo(@40); }]; } return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:NO]; //bug5234: 个人信息页,滑回不要有点击效果,包括夜间模式 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ if (indexPath.row == 1) { if ([_userBO.isAuth integerValue] == 0) { editSnameController *vc = [[editSnameController alloc]init]; vc.originStr = self.userBO.sname; [self.navigationController pushViewController:vc animated:YES]; } else { ShowTextMessage(@"您的帐号已做实名认证,不能修改。"); } }else if (indexPath.row == 3) { editMobileController *vc = [[editMobileController alloc] init]; [self.navigationController pushViewController:vc animated:YES]; }else if (indexPath.row == 4) { editMailController *vc = [[editMailController alloc] init]; [self.navigationController pushViewController:vc animated:YES]; }else if (indexPath.row == 5) { modifyAddressController *vc = [[modifyAddressController alloc] init]; vc.originStr = self.userBO.address; [self.navigationController pushViewController:vc animated:YES]; }else if (indexPath.row == 6) { //绑定社交账号 bindThirdAccountController *vc = [[bindThirdAccountController alloc]init]; vc.socialMap = self.userBO.weiboIdMap; [self.navigationController pushViewController:vc animated:YES]; }else if (indexPath.row == 7) { modifyPwdController *vc = [[modifyPwdController alloc] init]; [self.navigationController pushViewController:vc animated:YES]; }else if (indexPath.row == 8) { modifyAreaController *vc = [[modifyAreaController alloc] init]; [self.navigationController pushViewController:vc animated:YES]; }else if (indexPath.row == 9) { if ([_userBO.isAuth integerValue] == 0) { editSignController *vc = [[editSignController alloc] init]; vc.originStr = self.userBO.perDesc; [self.navigationController pushViewController:vc animated:YES]; } else { ShowTextMessage(@"您的帐号已做实名认证,不能修改。"); } } }); } #pragma mark - remote delegate - (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responsData { userBO *userBO = [TPUserDefault instance].userBO; if (userBO.weiboIdMap.count > 0) { if (userBO.weiboIdMap[@"WEIXIN"]) { [shareUtil thirdPartyOutLogin:weChatLoginType]; } if (userBO.weiboIdMap[@"SINA"]){ [shareUtil thirdPartyOutLogin:sinaWeiBoLoginType]; } if (userBO.weiboIdMap[@"RENREN"]){ [shareUtil thirdPartyOutLogin:renrenLoginType]; } if (userBO.weiboIdMap[@"QQCONTACT"]){ [shareUtil thirdPartyOutLogin:QQLoginType]; } if (userBO.weiboIdMap[@"EVERNOTE"]) { [shareUtil thirdPartyOutLogin:evernoteLoginType]; } if (userBO.weiboIdMap[@"YOUDAO"]) { [shareUtil thirdPartyOutLogin:youdaoLoginType]; } } [TPUserDefault instance].userBO = nil; // ShowMessage(@"退出登录", YES); [[NSNotificationCenter defaultCenter] postNotificationName:HAVELOGINOUT object:nil]; [self.navigationController popViewControllerAnimated:YES]; } - (void)remoteResponsFailed:(int)actionTag withMessage:(NSString *)message resultCode:(NSString *)code{ ShowTextMessage(message); } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end