// // XuToControlNameViewController.m // Ifish // // Created by imac on 2017/6/15. // Copyright © 2017年 lianlian. All rights reserved. // #import "XuToControlNameViewController.h" #import "XuToControlName.h" #import "UserExtendataArchaver.h" #import "RuSunChangeNameTextViewCell.h" #define XUTOCHCELL_AIR 50000 #define XUTOCHCELL_LIANGHT1 50001 #define XUTOCHCELL_LIANGHT2 50002 #define XUTOCHCELL_HULI 50003 #define XUTOCHCELL_WATER 50004 #define XUTOCHCELL_JIARE 50005 @interface XuToControlNameViewController () @end @implementation XuToControlNameViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.tableView.dataSource = self; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ if (section==0) { return 1; }else{ return 6; } } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 2; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section==0) { return [super baseViewLoadDeviceNameCell:indexPath intable:tableView]; } RuSunChangeNameTextViewCell*cell=[tableView dequeueReusableCellWithIdentifier:@"RuSunChangeNameTextViewCell"]; if (cell==nil) { cell= [[[NSBundle mainBundle]loadNibNamed:@"RuSunChangeNameTextViewCell" owner:self options:nil]lastObject]; } //控制原名 if (indexPath.row==5&&indexPath.section==1) { cell.lineImgView.image = [UIImage imageNamed:@"redact_line_last"]; } NSArray *titles= @[@"气泵",@"灯1",@"灯2",@"护理灯",@"水泵",@"加热棒"]; if (indexPath.section==1) { cell.chTitle.text = titles[indexPath.row]; } //自定义名字 XuToControlName *name = [UserExtendataArchaver currentXuToControlName:self.device.macAddress]; if (indexPath.section==1&&indexPath.row==0) { cell.chName.text = name.airPump; }else if (indexPath.section==1&&indexPath.row==1){ cell.chName.text = name.light1; }else if (indexPath.section==1&&indexPath.row==2){ cell.chName.text = name.light2; }else if (indexPath.section==1&&indexPath.row==3){ cell.chName.text = name.huLiDeng; }else if (indexPath.section==1&&indexPath.row==4){ cell.chName.text = name.waterPump; }else if (indexPath.section==1&&indexPath.row==5){ cell.chName.text = name.jiaRe; } cell.chName.delegate = self; cell.tag = 50000 + indexPath.row; return cell; } -(void)sureAction { //RunSunCHNameCustom 本地处理 保存按钮名称 不与服务器交互 XuToControlName *name = [[XuToControlName alloc] init]; RuSunChangeNameTextViewCell*cell1 = [self.view viewWithTag:XUTOCHCELL_AIR]; if (cell1.chName.text.length>3) { [self.view makeToast:@"气泵不能超过3个字"]; return; } if (cell1.chName.text.length==0) { [self.view makeToast:@"气泵不能为空"]; return; } name.airPump = cell1.chName.text; RuSunChangeNameTextViewCell*cell2 = [self.view viewWithTag:XUTOCHCELL_LIANGHT1]; if (cell2.chName.text.length>3) { [self.view makeToast:@"灯1不能超过3个字"]; return; } if (cell2.chName.text.length==0) { [self.view makeToast:@"灯1不能为空"]; return; } name.light1 = cell2.chName.text; RuSunChangeNameTextViewCell*cell3 = [self.view viewWithTag:XUTOCHCELL_LIANGHT2]; if (cell3.chName.text.length>3) { [self.view makeToast:@"灯2不能超过3个字"]; return; } if (cell3.chName.text.length==0) { [self.view makeToast:@"灯2不能为空"]; return; } name.light2 = cell3.chName.text; RuSunChangeNameTextViewCell*cell4 = [self.view viewWithTag:XUTOCHCELL_HULI]; if (cell4.chName.text.length>3) { [self.view makeToast:@"护理灯不能超过3个字"]; return; } if (cell4.chName.text.length==0) { [self.view makeToast:@"护理灯不能为空"]; return; } name.huLiDeng = cell4.chName.text; RuSunChangeNameTextViewCell*cell5 = [self.view viewWithTag:XUTOCHCELL_WATER]; if (cell5.chName.text.length>3) { [self.view makeToast:@"水泵不能超过3个字"]; return; } if (cell5.chName.text.length==0) { [self.view makeToast:@"水泵不能为空"]; return; } name.waterPump = cell5.chName.text; RuSunChangeNameTextViewCell*cell6 = [self.view viewWithTag:XUTOCHCELL_JIARE]; if (cell6.chName.text.length>3) { [self.view makeToast:@"加热棒不能超过3个字"]; return; } if (cell6.chName.text.length==0) { [self.view makeToast:@"加热棒不能为空"]; return; } name.jiaRe = cell6.chName.text; name.macAddress = self.device.macAddress; [UserExtendataArchaver saveXuToControlName:name]; [self upLoadDeviceName]; } /* #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