// // EditDeviceViewController.m // watch // // Created by xTT on 2017/7/17. // Copyright © 2017年 xTT. All rights reserved. // #import "EditDeviceViewController.h" #import "SelectContactVC.h" #import "EditDeviceHeadTableViewCell.h" #import "EidtDeviceContactWithDeviceTableViewCell.h" #import "NewTableViewCell.h" #import "NewOrdinaryTableViewCell.h" #import "LoginViewController.h" #import "QRcodeViewController.h" #import "MyUILabel.h" @interface EditDeviceViewController () { NSInteger _loginType;// 登录的类型 } @property (strong, nonatomic) UITextField *nameTextField; @property (nonatomic ,strong) NSString *girl_nan; @property (nonatomic ,strong) NSString *girl_nv; @property (nonatomic ,strong) UIView *headerView; @end @implementation EditDeviceViewController @synthesize myDataSource = _myDataSource; - (NSMutableArray *)myDataSource{ if (!_myDataSource) { _myDataSource = [[NSMutableArray alloc] initWithArray:@[@[@"头部信息",@"名称",@"性别",@"设备电话号码"],@[self.deviceType.integerValue == 3 ? @"与我的关系" : @"关系",@"生日",@"身高(cm)",@"体重(kg)"]]]; } return _myDataSource; } -(void)setIsAdd:(BOOL)isAdd{ _isAdd = isAdd; if(isAdd){ _isEdit = YES; } } -(void)setIsShowAllInfo:(BOOL)isShowAllInfo{ _isShowAllInfo = isShowAllInfo; if(isShowAllInfo){ self.myDataSource = [[NSMutableArray alloc] initWithArray:@[@[@"头部信息",@"名称",@"性别",@"设备电话号码"],@[self.deviceType.integerValue == 3 ? @"与我的关系" : @"关系",@"生日",@"身高(cm)",@"体重(kg)"]]]; }else{ self.myDataSource = [[NSMutableArray alloc] initWithArray:@[@[@"头部信息",@"名称",@"性别",@"设备电话号码"],@[self.deviceType.integerValue == 3 ? @"与我的关系" : @"关系",@"生日",@"身高(cm)",@"体重(kg)"]]]; } } -(void)setIsEdit:(BOOL)isEdit{ _isEdit = isEdit; [self.view endEditing:YES]; // 取消所有 文本框焦点 [self.myTableView reloadData]; } - (Device *)editDevice{ if (!_editDevice) { if(!self.isAdd){ _editDevice = cUser.cDevice; } if(!_editDevice){ _editDevice = [[Device alloc] init]; } if(!_editDevice.imei){ _editDevice.imei = self.IMEI; } } return _editDevice; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; _loginType = [myHelper getNowAccoutType:cUser]; } - (void)viewDidLoad { [super viewDidLoad]; self.deviceType = self.isAdd ? self.deviceType : cUser.cDevice.deviceType; self.girl_nan = self.deviceType.integerValue == 3 ? @"男" : @"男孩"; self.girl_nv = self.deviceType.integerValue == 3 ? @"女" : @"女孩"; [self zx_setRightBtnWithText:@"编辑" clickedBlock:^(ZXNavItemBtn * _Nonnull btn) { if([self.zx_navRightBtn.currentTitle isEqualToString:@"保存"] || [self.zx_navRightBtn.currentTitle isEqualToString:@"添加"]) [self rightBarItemClick]; if (!self.isAdd) [self navButtonState]; }]; if(self.isAdd) { self.zx_navTitle = @"添加设备"; [self.zx_navRightBtn setTitle:@"添加" forState:0]; self.isShowAllInfo = NO; } else { self.zx_navTitle = @"设备资料"; } [self initTableCellView]; } - (void)navButtonState { self.isEdit = YES; [self.zx_navRightBtn setTitle:@"保存" forState:0]; [self.zx_navRightBtn setTitleColor:mainColor forState:0]; self.zx_backBtnImageName = @""; [self.zx_navLeftBtn setTitle:@"取消" forState:0]; [self zx_leftClickedBlock:^(ZXNavItemBtn * _Nonnull btn) { if ([self.zx_navRightBtn.currentTitle isEqualToString:@"编辑"]) [self.navigationController popViewControllerAnimated:YES]; self.zx_backBtnImageName = @"icon_balck_return"; [self.zx_navRightBtn setTitle:@"编辑" forState:0]; [self.zx_navLeftBtn setTitle:@"" forState:0]; [self.zx_navRightBtn setTitleColor:KKTextBlackColor forState:0]; self.isEdit = NO; }]; [self.myTableView reloadData]; } /** 初始化tableViewCell */ -(void)initTableCellView{ self.myTableView.frame = CGRectMake(16, iPhoneX_NavHeight, ScreenWidth-32, ScreenHeight-iPhoneX_NavHeight); self.myTableView.tableHeaderView = self.headerView; self.myTableView.tableHeaderView.height = 208; //设备头像头部 [self.myTableView registerNib:[UINib nibWithNibName:@"EditDeviceHeadTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"EditDeviceHeadTableViewCellID"]; // 关系尾部 [self.myTableView registerNib:[UINib nibWithNibName:@"EidtDeviceContactWithDeviceTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"EidtDeviceContactWithDeviceTableViewCellID"]; // 中间的 cell [self.myTableView registerNib:[UINib nibWithNibName:@"NewOrdinaryTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"NewOrdinaryTableViewCellID"]; // 去线 self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.myTableView.backgroundColor = RGB(248 , 248, 248); } /** 修改,保存 和 添加的方法 */ - (void)rightBarItemClick { self.editDevice.name = self.nameTextField.text; // if(self.isEdit == YES || ([self.zx_navRightBtn.currentTitle isEqualToString:@"添加"])) // { if(!self.editDevice.name || self.editDevice.name.length == 0){ [UICommon MessageErrorText:@"请输入名称"]; }else if(!self.editDevice.sex || self.editDevice.sex.length == 0 ){ [UICommon MessageErrorText:@"请输入性别"]; }else if(!self.editDevice.birthday || self.editDevice.birthday.length == 0){ [UICommon MessageErrorText:@"请输入生日"]; }else if(!self.editDevice.height || self.editDevice.height.length == 0){ [UICommon MessageErrorText:@"请输入身高"]; }else if(!self.editDevice.weight || self.editDevice.weight.length == 0){ [UICommon MessageErrorText:@"请输入体重"]; }else if(!self.editDevice.phone || self.editDevice.phone.length == 0){ [UICommon MessageErrorText:@"请输入设备电话号码"]; } else { WEAKSELF if(self.isAdd) { /// 添加设备 [cUser addDeviceWithDevice:self.editDevice success:^(id responseObject) { cUser.cDevice.image = self.editDevice.image; cUser.cDevice.phone = self.editDevice.phone; cUser.cDevice.name = self.editDevice.name; cUser.cDevice.avator = self.editDevice.avator; [weakSelf quitThisVC]; } failure:^(id faiObject) { }]; } else { /// 编辑资料 [self saveAction]; } } // } // else if (self.isEdit == NO) // { // self.isEdit = YES; // } } -(void)saveAction{ // 防止 cell中的 TextField 重用导致的 my_phone 错乱问题 self.editDevice.my_phone = cUser.phone; WEAKSELF [self.editDevice saveDeviceInfoSuccess:^(id responseObject) { cUser.cDevice.image = self.editDevice.image; cUser.cDevice.phone = self.editDevice.phone; cUser.cDevice.name = self.editDevice.name; cUser.cDevice.avator = self.editDevice.avator; [weakSelf quitThisVC]; } failure:^(NSError *error) { }]; } -(void)goBack:(id)sender { [self.view endEditing:YES]; if(!self.isAdd){ if(self.isEdit){ WEAKSELF LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:nil message:@"是否保存修改" style:LGAlertViewStyleAlert buttonTitles:@[@"确定"] cancelButtonTitle:@"取消" destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { [weakSelf rightBarItemClick]; } cancelHandler:^(LGAlertView *alertView) { [weakSelf quitThisVC]; } destructiveHandler:^(LGAlertView *alertView) { }]; [alertView showAnimated:YES completionHandler:nil]; }else{ [self quitThisVC]; } }else{ [self quitThisVC]; } } -(void)quitThisVC { if(self.isAdd) { //MARK: 为了让新添加的设备在主位置上 [User currentUser].cDevice = nil; [[User currentUser].myDevices removeAllObjects]; //添加模式 //如果是登录页面进去的添加模式 dissmiss 登录页面 if ([self.navigationController.viewControllers.firstObject isKindOfClass:[LoginViewController class]]) { [self dismissViewControllerAnimated:YES completion:nil]; NSLog( @"==========1=========="); }else{ //回到主页面 [self.navigationController popToRootViewControllerAnimated:YES]; // [self.navigationController popViewControllerAnimated:YES]; NSLog(@"==========2=========="); } [[NSNotificationCenter defaultCenter] postNotificationName:@"device_add" object:nil]; }else { //修改模式 //回到主页面 // [self.navigationController popToRootViewControllerAnimated:YES]; [UICommon MessageSuccessText:@"保存成功" isImg:NO]; AfterDispatch(1, ^{ [self.navigationController popViewControllerAnimated:YES]; }); NSLog(@"==========3=========="); } } /** 显示完善资料的切换 */ -(void)perfectInformationAction{ self.isShowAllInfo = YES; [self.myTableView reloadData]; } /** 解除绑定 方法 */ - (void)unbundlingBtn:(id)sender { // 管理员显示--- 您是设备的管理员,如果您进行解绑,其他绑定该设备的用户,将自动解绑,确认解除绑定吗? NSString *msg = @"是否解除绑定?"; if([cUser.cDevice.identity isEqualToString:@"admin"]){ msg = @"您是设备的管理员,如果您进行解绑,其他绑定该设备的用户,将自动解绑,确认解除绑定吗?"; } UIAlertController *sheet = [myHelper getAlertWithTitle:msg actionTitles:@[@"确定"] style:UIAlertControllerStyleAlert block:^(UIAlertAction *action) { if ([action.title isEqualToString:@"确定"]) { NSMutableDictionary * parameters = [NSMutableDictionary dictionary]; [parameters setObject:cUser.cDevice.imei forKey:@"imei"]; [cUser deleteDeviceSuccess:^(id responseObject) { //回到首页 [self.navigationController popToRootViewControllerAnimated:YES]; } failure:^(id faiObject) { }]; } }]; [self presentViewController:sheet animated:YES completion:nil]; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ NSString *title = self.myDataSource[indexPath.section][indexPath.row]; if (!self.isShowAllInfo && [title isEqualToString:@"完善设备资料"]){ return 0; } return 60; // 50--》60 } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ NSString *title = self.myDataSource[indexPath.section][indexPath.row]; if(indexPath.section == 0 && indexPath.row == 0) { //头部信息 EditDeviceHeadTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"EditDeviceHeadTableViewCellID" forIndexPath:indexPath]; [cell setDevice:self.editDevice WithStatus:self.isAdd isEdting:self.isEdit]; return cell; } else if(indexPath.section == 1 && indexPath.row == 0) { // 关系 NewOrdinaryTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NewOrdinaryTableViewCellID" forIndexPath:indexPath]; cell.accessoryType = UITableViewCellAccessoryNone; cell.aTitleLabel.text = title; cell.deviceType = self.deviceType; [cell setDevice:self.editDevice]; cell.contactLabel.textColor = KKBlack20; cell.contactLabel.font = FontBold_(14); [UICommon ui_uiViewFillet:cell.bounds Viewdirection:PYUIdirectionTop toView:cell sizeMake:12]; if(self.isEdit && ([self.editDevice.identity isEqualToString:@"admin"] || _loginType == 3)) { //需 管理员关系 或者是imei游客登录 且 在编辑状态下 才能修改 cell.userInteractionEnabled = YES; } else { if(self.isEdit) { cell.userInteractionEnabled = YES; } else { //cell.contactLabel.textColor = RGB(204, 204, 204); cell.userInteractionEnabled = NO; } } [cell.contactImageView mas_remakeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(cell); make.right.equalTo(cell.mas_right).inset(15); make.width.height.mas_equalTo(40); }]; [cell.contactLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(cell.mas_right).inset(60); make.centerY.equalTo(cell); }]; return cell; } else if (!self.isShowAllInfo && [title isEqualToString:@"完善设备资料"]) { UITableViewCell *cell = [UITableViewCell new]; return cell; } else { NewOrdinaryTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NewOrdinaryTableViewCellID" forIndexPath:indexPath]; if ((indexPath.section == 0 && indexPath.row == 3) || (indexPath.section == 1 && indexPath.row == 3)) [UICommon ui_uiViewFillet:cell.bounds Viewdirection:PYUIdirectionBotton toView:cell sizeMake:12]; cell.accessoryType = UITableViewCellAccessoryNone; cell.aTitleLabel.text = title; cell.aTextField.textAlignment = NSTextAlignmentRight; cell.aTextField.textColor = KKBlack20; cell.aTextField.font = FontBold_(14); //在区域的尾部 隐藏线 NSInteger lastIndex = [self.myDataSource[indexPath.section] count] -1; if(lastIndex < 0){ lastIndex = 0; } if(indexPath.section == 0 && indexPath.row == lastIndex){ cell.lineView.hidden = YES; }else if (indexPath.section == 1 && indexPath.row == lastIndex){ cell.lineView.hidden = YES; }else{ cell.lineView.hidden = NO; } // cell.aTextFRightNSLC.constant = 15; // 需要设置一下默认 设置 ,防止 重用 cell input 错乱 [cell defaultInputView]; if(self.isEdit && ([self.editDevice.identity isEqualToString:@"admin"] || _loginType == 3)){ //需 管理员关系 或者是imei游客登录 且 在编辑状态下 才能修改 cell.userInteractionEnabled = YES; } else { if(self.isEdit) { //成员编辑状态下 /* 成员可编辑的状态 @"本机电话号码", @"生日", @"身高(cm)", @"体重(kg)" */ if([title isEqualToString:@"本机电话号码"] || [title isEqualToString:@"生日"] || [title isEqualToString:@"身高(cm)"] || [title isEqualToString:@"体重(kg)"]) { cell.userInteractionEnabled = YES; } else { if(self.isAdd){ cell.userInteractionEnabled = YES; }else{ // cell.aTextField.textColor = [UIColor lightGrayColor]; cell.userInteractionEnabled = NO; } } } else { cell.aTextField.textColor = (![self.editDevice.identity isEqualToString:@"admin"] && ([title isEqualToString:@"头像"] || [title isEqualToString:@"性别"] || [title isEqualToString:@"名称"] || [title isEqualToString:@"设备电话号码"])) ? [UIColor lightGrayColor] : KKBlack20; cell.userInteractionEnabled = NO; } } if(!self.isAdd){ // if ([title isEqualToString:@"名称"]) { cell.aTextField.placeholder = @"请输入名称"; cell.aTextField.text = self.editDevice.name; self.nameTextField = cell.aTextField; cell.aTextField.delegate = self; //不实现回调 cell.block = nil; return cell; } if ([title isEqualToString:@"性别"]) { cell.aTextField.placeholder = @"选择性别"; NSInteger index = ([self.editDevice.sex isEqualToString: @"girl"]) ? -1 : 0; [cell numberInputViewWithStartNum:-1 EndNum:1 WithIndex:index]; cell.aTextField.text = ([self.editDevice.sex isEqualToString: @"girl"]) ? self.girl_nv : self.girl_nan; } if ([title isEqualToString:@"生日"]) { NSDateFormatter *formatter = [NSDateFormatter new]; [formatter setDateFormat:@"yyyy-MM-dd"]; [cell timeInputViewWithModel:UIDatePickerModeDate WithData:[formatter dateFromString:self.editDevice.birthday]]; //日期 cell.aTextField.placeholder = @"eg:1994-01-01"; cell.aTextField.text = (self.editDevice.birthday) ?:@""; } if ([title isEqualToString:@"身高(cm)"]) { [cell numberInputViewWithStartNum:50 EndNum:201 WithIndex:[self.editDevice.height integerValue]]; cell.aTextField.placeholder = @"输入身高"; cell.aTextField.text = (self.editDevice.height) ?:@""; } if ([title isEqualToString:@"体重(kg)"]) { [cell numberInputViewWithStartNum:10 EndNum:101 WithIndex:[self.editDevice.weight integerValue]]; cell.aTextField.placeholder = @"输入体重"; cell.aTextField.text = (self.editDevice.weight) ?:@""; } if ([title isEqualToString:@"IMEI/MEID号"]) { cell.aTextField.placeholder = @"请输入IMEI/MEID号"; cell.aTextField.enabled = NO; cell.aTextField.textColor = [UIColor lightGrayColor]; cell.aTextField.text = self.editDevice.imei; } if ([title isEqualToString:@"设备电话号码"]) { cell.aTextField.keyboardType = UIKeyboardTypePhonePad; cell.aTextField.placeholder = @"请输入设备电话号码"; cell.aTextField.text = (self.editDevice.phone) ?:@""; cell.aTextField.delegate = self; } if ([title isEqualToString:@"本机电话号码"]) { cell.aTextField.keyboardType = UIKeyboardTypePhonePad; cell.aTextField.placeholder = @"本机电话号码"; // cell.aTextField.enabled = NO; // cell.aTextField.textColor = [UIColor lightGrayColor]; cell.aTextField.text = (self.editDevice.my_phone) ?:cUser.phone; cell.aTextField.delegate = self; } WEAKSELF cell.block = ^(NSString *text, NewTableViewCell *blockCell){ blockCell.aTextField.text = text; if ([title isEqualToString:@"性别"]) { weakSelf.editDevice.sex = ([text isEqualToString:@"0"]) ? @"girl" : @"boy"; blockCell.aTextField.text = ([text isEqualToString:@"0"]) ? self.girl_nv : self.girl_nan; //需要刷新头部信息 [weakSelf.myTableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationNone]; }else if ([title isEqualToString:@"生日"]) { weakSelf.editDevice.birthday = text; }else if([title isEqualToString:@"身高(cm)"]){ weakSelf.editDevice.height = text; }else if([title isEqualToString:@"体重(kg)"]){ weakSelf.editDevice.weight = text; }else if ([title isEqualToString:@"设备电话号码"]) { weakSelf.editDevice.phone = text; }else if ([title isEqualToString:@"本机电话号码"]) { weakSelf.editDevice.my_phone = text; } }; }else{ //添加状态 if ([title isEqualToString:@"名称"]) { cell.aTextField.placeholder = @"请输入名称"; cell.aTextField.text = self.isAdd && self.deviceType.integerValue == 3 ? @"" : self.editDevice.name; self.nameTextField = cell.aTextField; cell.aTextField.delegate = self; //不实现回调 cell.block = nil; return cell; } if ([title isEqualToString:@"性别"]) { cell.aTextField.placeholder = @"选择性别"; cell.aTextField.text = ([self.editDevice.sex isEqualToString: @"girl"]) ? self.girl_nv : self.girl_nan; NSInteger index = ([self.editDevice.sex isEqualToString: @"girl"]) ? -1 : 0; [cell numberInputViewWithStartNum:-1 EndNum:1 WithIndex:index]; } if ([title isEqualToString:@"生日"]) { NSDateFormatter *formatter = [NSDateFormatter new]; [formatter setDateFormat:@"yyyy-MM-dd"]; [cell timeInputViewWithModel:UIDatePickerModeDate WithData:[formatter dateFromString:self.editDevice.birthday]]; //日期 cell.aTextField.placeholder = @"eg:1994-01-01"; cell.aTextField.text = self.editDevice.birthday; } if ([title isEqualToString:@"身高(cm)"]) { [cell numberInputViewWithStartNum:50 EndNum:201 WithIndex:[self.editDevice.height integerValue]]; cell.aTextField.placeholder = @"输入身高"; cell.aTextField.text = self.editDevice.height; } if ([title isEqualToString:@"体重(kg)"]) { [cell numberInputViewWithStartNum:10 EndNum:101 WithIndex:[self.editDevice.weight integerValue]]; cell.aTextField.placeholder = @"输入体重"; cell.aTextField.text = self.editDevice.weight; } if ([title isEqualToString:@"IMEI/MEID号"]) { cell.aTextField.placeholder = @"请输入IMEI/MEID号"; cell.aTextField.enabled = NO; cell.aTextField.textColor = [UIColor lightGrayColor]; cell.aTextField.text = self.editDevice.imei; } if ([title isEqualToString:@"设备电话号码"]) { cell.aTextField.keyboardType = UIKeyboardTypePhonePad; cell.aTextField.placeholder = @"请输入设备电话号码"; cell.aTextField.delegate = self; } if ([title isEqualToString:@"本机电话号码"]) { cell.aTextField.keyboardType = UIKeyboardTypePhonePad; cell.aTextField.placeholder = @"本机电话号码"; cell.aTextField.delegate = self; // cell.aTextField.enabled = NO; // cell.aTextField.textColor = [UIColor lightGrayColor]; if(self.editDevice.my_phone){ cell.aTextField.text = self.editDevice.my_phone; }else{ cell.aTextField.text = cUser.phone; self.editDevice.my_phone = cUser.phone; } } WEAKSELF cell.block = ^(NSString *text, NewTableViewCell *blockCell){ blockCell.aTextField.text = text; if ([title isEqualToString:@"性别"]) { weakSelf.editDevice.sex = ([text isEqualToString:@"0"]) ? @"girl" : @"boy"; blockCell.aTextField.text = ([text isEqualToString:@"0"]) ? self.girl_nv : self.girl_nan; //需要刷新头部信息 [weakSelf.myTableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationNone]; }else if ([title isEqualToString:@"生日"]) { weakSelf.editDevice.birthday = text; }else if([title isEqualToString:@"身高(cm)"]){ weakSelf.editDevice.height = text; }else if([title isEqualToString:@"体重(kg)"]){ weakSelf.editDevice.weight = text; }else if ([title isEqualToString:@"IMEI/MEID号"]) { weakSelf.editDevice.imei = text; }else if ([title isEqualToString:@"设备电话号码"]) { weakSelf.editDevice.phone = text; }else if ([title isEqualToString:@"本机电话号码"]) { weakSelf.editDevice.my_phone = text; } }; } return cell; } return nil; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ NSString *title = self.myDataSource[indexPath.section][indexPath.row]; if ([title isEqualToString:@"头部信息"]){ if((self.isEdit && [self.editDevice.identity isEqualToString:@"admin"]) || self.isAdd){ //管理员 且是编辑状态 || 是添加状态 UIAlertController *sheet = [myHelper getAlertWithPicture:^(UIImagePickerController *imagePickerVC) { imagePickerVC.delegate = self; [self presentViewController:imagePickerVC animated:YES completion:^{}]; }]; if(sheet){ [self presentViewController:sheet animated:YES completion:nil]; } } } if([title isEqualToString:self.deviceType.integerValue == 3 ? @"与我的关系" : @"关系"]){ if (!self.isEdit){ return; } //跳转到选择关系页面 SelectContactVC * vc = [SelectContactVC new]; vc.deviceType = self.deviceType; vc.contact = self.editDevice.relationship; vc.contactId = self.editDevice.relationship_image_id; vc.phone = self.editDevice.my_phone; //本机电话号码 WEAKSELF vc.selectContactBack = ^(NSString *contact, NSNumber *contactId, NSString *phone, NSString *name) { weakSelf.editDevice.relationship = contact; weakSelf.editDevice.relationship_image_id = contactId; weakSelf.editDevice.my_phone = phone; if(!self.isAdd){ weakSelf.editAndSaveBarButton.image = [UIImage imageNamed:@"icon_equipment_information_save"]; } [weakSelf.myTableView reloadData]; }; [self.navigationController pushViewController:vc animated:YES]; } } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ // if(section == 1 ) // { // return 20; // } return section == 1 ? 40 : 0.1; // return [super tableView:tableView heightForHeaderInSection:section]; } -(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ if(section == 1) { UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SWIDTH, 40)]; view.backgroundColor = [UIColor clearColor]; UILabel *titleLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:Font_(12) textColor:RGB(204, 204, 204) text:@"您可修改自己的头像、名称等信息" Radius:0]; [view addSubview:titleLabel]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(view).offset(15); make.centerY.equalTo(view); }]; // UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 5, SWIDTH, 1)]; // lineView.backgroundColor = RGB(245, 245, 245); // [view addSubview:lineView]; return view; } return nil; } -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ if (section == self.myDataSource.count-1) { //最后一个 if(self.isAdd){ // 是添加状态 if(!self.isShowAllInfo){ //且 未显示完整状态 // UIView *view =[[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 50)]; // UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; // button.frame = CGRectMake(0, 0, ScreenWidth, 50); // [button setTitle:@"完善完整资料" forState:0]; // [button setTitleColor:mainColor forState:0]; // [button.titleLabel setFont:[UIFont systemFontOfSize:13]]; // [button setImage:[UIImage imageNamed:@"icon_perfect_information"] forState:0]; // [button addTarget:self action:@selector(perfectInformationAction) forControlEvents:UIControlEventTouchUpInside]; // [view addSubview:button]; // return view; } }else{ // // 展示状态 // UIView *view =[[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 84)]; // UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; // button.frame = CGRectMake(14, 20, ScreenWidth-24, 44); // button.layer.cornerRadius = 3; // button.layer.masksToBounds = YES; // [button setTitle:@"解除与设备的绑定" forState:0]; // [button setBackgroundColor:mainColor]; // [button setTintColor:[UIColor whiteColor]]; // [button.titleLabel setFont:[UIFont systemFontOfSize:13]]; // [button addTarget:self action:@selector(unbundlingBtn:) forControlEvents:UIControlEventTouchUpInside]; // [view addSubview:button]; // return view; } } return nil; } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ if (section == self.myDataSource.count-1) { //最后一个 if(self.isAdd){ // 是添加状态 if(!self.isShowAllInfo){ //且 未显示完整状态 return 50; } }else{ return 0.01; } } return 0.01; } #pragma mark UIImagePickerControllerDelegate - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated { if ([UIDevice currentDevice].systemVersion.floatValue < 11) { return; } if ([viewController isKindOfClass:NSClassFromString(@"PUPhotoPickerHostViewController")]) { [viewController.view.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if (obj.frame.size.width < 42) { [viewController.view sendSubviewToBack:obj]; *stop = YES; } }]; } } - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [picker dismissViewControllerAnimated:YES completion:^{}]; UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage]; self.editDevice.image = image; [self.myTableView reloadData]; } - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { [picker dismissViewControllerAnimated:YES completion:nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } //MARK: UITextFieldDelegate 限制字数 和输入的 字符 -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ // 最终的结果 NSString *str = textField.text; NSString *resultStr = [str stringByReplacingCharactersInRange:range withString:string]; if([self.nameTextField isEqual:textField]){ if(resultStr.length > 8){ return NO; }else{ self.editDevice.name = resultStr; return YES; } } if([@"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" containsString:string]){ if(resultStr.length > 15){ return NO; }else{ return YES; } }else{ if([string isEqualToString:@""]){ return YES; } return NO; } } - (UIView *)headerView { WEAKSELF if (!_headerView) { _headerView = [UIView new]; _headerView.backgroundColor = KKWhiteColorColor; _headerView.frame = CGRectMake(0, 15, ScreenWidth-30, 193); [UICommon ui_uiViewFillet:_headerView.frame Viewdirection:PYUIdirectionTop toView:_headerView sizeMake:12]; UIButton *qrImgBtn = [UICommon ui_buttonSimple:CGRectZero font:Font_(0) normalColor:KKWhiteColorColor normalText:@"" click:^(id x) { [weakSelf codeShowAction]; }]; [qrImgBtn setImage:[self.editDevice.identity isEqualToString:@"admin"] ? ImageName_(@"comm_dev_bg_icon_y") : ImageName_(@"comm_dev_bg_icon") forState:0]; [_headerView addSubview:qrImgBtn]; [qrImgBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(_headerView); make.top.equalTo(_headerView).offset(20); make.size.mas_equalTo(CGSizeMake(128, 128)); }]; UIButton *qrTitleBtn = [UICommon ui_buttonSimple:CGRectZero font:Font_(12) normalColor:KKBlack20 normalText:@" 设备二维码" click:^(id x) { [weakSelf codeShowAction]; }]; qrTitleBtn.layer.cornerRadius = 14; qrTitleBtn.layer.masksToBounds = YES; qrTitleBtn.backgroundColor = RGB(248, 247, 247); [qrTitleBtn setImage:ImageName_(@"comm_dev_qrcode_icon") forState:0]; [_headerView addSubview:qrTitleBtn]; [qrTitleBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(_headerView); make.top.equalTo(qrImgBtn.mas_bottom).offset(16); make.size.mas_equalTo(CGSizeMake(102, 28)); }]; } return _headerView; } -(void)codeShowAction { [UICommon PusXibViewController:[QRcodeViewController new] :@"QRcodeViewController"]; } @end