// // XuToSetViewController.m // Ifish // // Created by imac on 16/4/22. // Copyright © 2016年 imac. All rights reserved. // #import "XuToSetViewController.h" #import "SetTimeCell.h" #import "SecondSetTimeCell.h" #import "SetTimeModel.h" #import "SetSelectorTime.h" //#import "AsyncSocket.h" #import "setWaringTpModel.h" #import "appLogin.h" #import "workTypeModel.h" #import "SetSelectorTime.h" #define TIME_TAG 300 #import "MyPickerView.h" #import "searchDeviceModel.h" #import "XutoBackMsgModel.h" #import "MydatePickerView.h" #define SET_CELL_TAG 2000 #define MYSWITCH_TAG 3000 #import "CenterViewController.h" #import "TimerSateModel.h" #import "TemperatureSetCell.h" #import "TemperatureSetModel.h" #import "AppDelegate.h" #import "BrightnessCell.h" #import "GuidengKaiGuanModel.h" #import "GuiDengViewCell.h" #import "ChangeWaterCell.h" #import "remindCyclePic.h" #import "BrightnessModel.h" #import "CreatErWeiMaController.h" #import "UINavigationBar+Background.h" @interface XuToSetViewController () { MydatePickerView*_mydatepicView; MyPickerView* _mypicView; remindCyclePic*_remindPic; dispatch_queue_t _mainQueue; BOOL _huanShuiSwitchIsOn; } @property(nonatomic,strong)NSIndexPath*indexpath; @property(nonatomic,copy)NSString*statString; @property(nonatomic,copy)NSString*endString; @property(nonatomic,strong)UIView*lodingbackView; @property(nonatomic,copy)NSString*nextChangeDateLabel; @property(nonatomic,strong)setRemindWaterModel*waterInfmodel; @property(nonatomic) NSInteger tian; @end @implementation XuToSetViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. if (_isNewDevice) { [self.navigationController.navigationBar resetBackgroundImage]; } _waterInfmodel=[[setRemindWaterModel alloc]init]; [super viewDidLoad]; _mainQueue = dispatch_get_main_queue(); self.navigationController.navigationBar.backItem.title=@""; [self addTitleViewWithTitle:@"设置"]; [self initData]; [self creatIndicatorView]; self.tableView.backgroundColor=COLOR_MIAN; // if ([self.currentdevice.isMaster isEqualToString:@"1"]) { // UIBarButtonItem*rightItem=[[UIBarButtonItem alloc]initWithTitle:@"分享设备" style: UIBarButtonItemStyleDone target:self action:@selector(threeItemClick)]; // rightItem.tintColor=[UIColor whiteColor]; // self.navigationItem.rightBarButtonItem=rightItem; // } self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone; } -(void)threeItemClick{ CreatErWeiMaController*vc=[[CreatErWeiMaController alloc]init] ; vc.erdevicemodel=self.currentdevice; [self.navigationController pushViewController:vc animated:YES]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)initData{ self.titleArr=@[@[@"预警设置",@"换水提醒"],@[@"时段一",@"时段二"],@[@"时段一",@"时段二"],@[@"时段一",@"时段二"]]; XutoBackMsgModel *backmodel=[[DataCenter defaultDtacenter]valueForKey:@"xutoBackInfo"]; if (backmodel) { NSString*low=backmodel.miniTp; NSString*heigh=backmodel.maxTp; UInt64 lowten=[dataContorl hexToTen:low]; UInt64 heighten=[dataContorl hexToTen:heigh]; float formatlow=lowten/10; float formatheigh=heighten/10; NSString*wenduString=[NSString stringWithFormat:@"%.0f~%.0f°C",formatlow,formatheigh]; // 十六进制 NSString*startTimeHex1=[backmodel.timer1 substringWithRange:NSMakeRange(4, 4)]; NSString*endTimeHex1=[backmodel.timer1 substringWithRange:NSMakeRange(8, 4)]; // 十进制 NSString*startTimeTen1=[dataContorl hexStringToDateString:startTimeHex1]; NSString*endTimeTen1=[dataContorl hexStringToDateString:endTimeHex1]; NSString*setTim1=[NSString stringWithFormat:@"%@~%@",startTimeTen1,endTimeTen1]; // 十六进制 NSString*startTimeHex2=[backmodel.timer2 substringWithRange:NSMakeRange(4, 4)]; NSString*endTimeHex2=[backmodel.timer2 substringWithRange:NSMakeRange(8, 4)]; // 十进制 NSString*startTimeTen2=[dataContorl hexStringToDateString:startTimeHex2]; NSString*endTimeTen2=[dataContorl hexStringToDateString:endTimeHex2]; NSString*setTim2=[NSString stringWithFormat:@"%@~%@",startTimeTen2,endTimeTen2]; // 十六进制 NSString*startTimeHex3=[backmodel.timer3 substringWithRange:NSMakeRange(4, 4)]; NSString*endTimeHex3=[backmodel.timer3 substringWithRange:NSMakeRange(8, 4)]; // 十进制 NSString*startTimeTen3=[dataContorl hexStringToDateString:startTimeHex3]; NSString*endTimeTen3=[dataContorl hexStringToDateString:endTimeHex3]; NSString*setTim3=[NSString stringWithFormat:@"%@~%@",startTimeTen3,endTimeTen3]; // 十六进制 NSString*startTimeHex4=[backmodel.timer4 substringWithRange:NSMakeRange(4, 4)]; NSString*endTimeHex4=[backmodel.timer4 substringWithRange:NSMakeRange(8, 4)]; // 十进制 NSString*startTimeTen4=[dataContorl hexStringToDateString:startTimeHex4]; NSString*endTimeTen4=[dataContorl hexStringToDateString:endTimeHex4]; NSString*setTim4=[NSString stringWithFormat:@"%@~%@",startTimeTen4,endTimeTen4]; // 十六进制 NSString*startTimeHex5=[backmodel.timer5 substringWithRange:NSMakeRange(4, 4)]; NSString*endTimeHex5=[backmodel.timer5 substringWithRange:NSMakeRange(8, 4)]; // 十进制 NSString*startTimeTen5=[dataContorl hexStringToDateString:startTimeHex5]; NSString*endTimeTen5=[dataContorl hexStringToDateString:endTimeHex5]; NSString*setTim5=[NSString stringWithFormat:@"%@~%@",startTimeTen5,endTimeTen5]; // 十六进制 NSString*startTimeHex6=[backmodel.timer6 substringWithRange:NSMakeRange(4, 4)]; NSString*endTimeHex6=[backmodel.timer6 substringWithRange:NSMakeRange(8, 4)]; // 十进制 NSString*startTimeTen6=[dataContorl hexStringToDateString:startTimeHex6]; NSString*endTimeTen6=[dataContorl hexStringToDateString:endTimeHex6]; NSString*setTim6=[NSString stringWithFormat:@"%@~%@",startTimeTen6,endTimeTen6]; self.timeArr=@[@[wenduString,@"设置时段"],@[setTim1,setTim2],@[setTim3,setTim4],@[setTim5,setTim6,@""]]; }else{ [self showTitle:@"" messsage:@"设备已离线"]; self.timeArr=@[@[@"20~30°C",@"2:00~5:00"],@[@"2:00~5:00",@"2:00~5:00"],@[@"2:00~5:00",@"2:00~5:00"],@[@"2:00~5:00",@"2:00~5:00",@""]]; } } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 4; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (section == 0) { return 3; }else if (section == 3){ return 3; }else{ return 2; } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { XutoBackMsgModel *backmodel=[[DataCenter defaultDtacenter]valueForKey:@"xutoBackInfo"]; static NSString *cellID=@"kongCell"; UITableViewCell *kongCell=[tableView dequeueReusableCellWithIdentifier:cellID]; if (kongCell==nil) { kongCell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID]; } if (indexPath.section==0&&indexPath.row==0){ TemperatureSetCell*cell=[tableView dequeueReusableCellWithIdentifier:@"TemperatureSetCell"]; if (cell==nil) { cell=[[[NSBundle mainBundle]loadNibNamed:@"TemperatureSetCell" owner:self options:nil]lastObject]; } cell.tag=indexPath.row +SET_CELL_TAG+indexPath.section*10; TemperatureSetModel*model=[[TemperatureSetModel alloc]init]; model.title=self.titleArr[indexPath.section][indexPath.row]; cell.titleLabel.text=model.title; model.temperatureLabel=self.timeArr[indexPath.section][indexPath.row]; cell.temperaturelabel.text=model.temperatureLabel; [cell.temPSwitch addTarget:self action:@selector(xuTotempSwitchAction:) forControlEvents:UIControlEventTouchUpInside]; if (backmodel) { if ([backmodel.baojingSwitch isEqualToString:@"01"]) { [cell.temPSwitch setBackgroundImage:[UIImage imageNamed:@"greenbtn_big"] forState:UIControlStateNormal]; cell.temPSwitch.selected = NO; }else{ [cell.temPSwitch setBackgroundImage:[UIImage imageNamed:@"graybtn_big"] forState:UIControlStateNormal]; cell.temPSwitch.selected = YES; } }else{ } return cell; }else if (indexPath.section==0&&indexPath.row==1){ // 换水提醒 if (![self.currentdevice.waterRemind isEqual:[NSNull null]]) { ChangeWaterCell*cell=[tableView dequeueReusableCellWithIdentifier:@"ChangeWaterCell"]; if (cell==nil) { cell=[[[NSBundle mainBundle]loadNibNamed:@"ChangeWaterCell" owner:self options:nil]lastObject]; } [cell.ChangeWaterSwitch addTarget:self action:@selector(xuTochangeWaterSwitch:) forControlEvents:UIControlEventTouchUpInside]; if ([self.waterInfmodel.waterremind isEqualToString:@"1"]) { [cell.ChangeWaterSwitch setBackgroundImage:[UIImage imageNamed:@"greenbtn_big"] forState:UIControlStateNormal]; cell.ChangeWaterSwitch.selected = NO; cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"firstSetCell"]]; _huanShuiSwitchIsOn=YES; }else{ [cell.ChangeWaterSwitch setBackgroundImage:[UIImage imageNamed:@"graybtn_big"] forState:UIControlStateNormal]; cell.ChangeWaterSwitch.selected = YES; _huanShuiSwitchIsOn=NO; cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"set_cellBack"]]; } if (self.waterInfmodel.remindcycle == 0) { //在未获取换水信息时暂时显示 cell.huanshuiDaylabel.text=@"换水时间"; }else{ cell.huanshuiDaylabel.text=[NSString stringWithFormat:@"%ld天",(long)self.waterInfmodel.remindcycle]; NSLog(@"ce;;%@",cell.huanshuiDaylabel.text); NSLog(@"222"); } return cell; }else{ kongCell.textLabel.text =@"错误信息 waterRemind null"; return kongCell; } }else if (indexPath.section==0&&indexPath.row==2){ static NSString*nextHuanShuiLablecellId=@"labelcell"; UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:nextHuanShuiLablecellId]; if (cell==nil) { cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nextHuanShuiLablecellId]; } if (_huanShuiSwitchIsOn) { cell.textLabel.text=[NSString stringWithFormat:@"下次换水时间:%@",self.waterInfmodel.remindDate]; if (!self.waterInfmodel.remindDate) { cell.textLabel.text=[NSString stringWithFormat:@"下次换水时间:%@",self.nextChangeDateLabel]; } cell.textLabel.font=[UIFont systemFontOfSize:15]; [cell.textLabel sizeToFit]; cell.textLabel.textColor =[UIColor colorWithRed:146.0/256.0 green:146.0/256.0 blue:146.0/256.0 alpha:1]; cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"secondSetCell"]]; }else{ cell.textLabel.text=@""; } cell.userInteractionEnabled = NO; return cell; }else{ if (indexPath.section==3&&indexPath.row==2) { //最后插入一个cell达到 椭圆底效果 static NSString*cellId=@"lastSectlastcell"; UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:cellId]; if (cell==nil) { cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellId]; } cell.backgroundView =[ [UIImageView alloc] initWithImage:[UIImage imageNamed:@"secondSetCell"]]; cell.userInteractionEnabled = NO; return cell; }else{ SetTimeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SetTimeCell"]; if (cell==nil) { cell=[[[NSBundle mainBundle]loadNibNamed:@"SetTimeCell" owner:self options:nil]lastObject]; } if (indexPath.section==0&&indexPath.row==0) { cell.mySwitchButton.hidden=YES; }else{ cell.mySwitchButton.hidden=NO; } SetTimeModel*model=[[SetTimeModel alloc]init]; model.title=self.titleArr[indexPath.section][indexPath.row]; cell.titleLabel.text=model.title; model.timestring=self.timeArr[indexPath.section][indexPath.row]; cell.timeLabel.text=model.timestring; cell.timeLabel.tag=TIME_TAG+indexPath.section*10+indexPath.row; if (indexPath.section!=0 && !(indexPath.section==3&&indexPath.row==2)) { cell.tag=indexPath.row +SET_CELL_TAG+indexPath.section*10; cell.mySwitchButton.tag=indexPath.row +MYSWITCH_TAG+indexPath.section*10; } if (indexPath.section!=0 && !(indexPath.section==3&&indexPath.row==2)) { if (indexPath.section==1&&indexPath.row==0) {//开关一 NSString*state=[backmodel.timer1 substringWithRange:NSMakeRange(2, 2)]; if ([state isEqualToString:@"00"]) { [cell.mySwitchButton setImage:[UIImage imageNamed:@"Switch-Off"] forState:UIControlStateNormal]; }else{ [cell.mySwitchButton setImage:[UIImage imageNamed:@"Switch-On"] forState:UIControlStateNormal]; } } if (indexPath.section==1&&indexPath.row==1) {//开关2 NSString*state=[backmodel.timer2 substringWithRange:NSMakeRange(2, 2)]; if ([state isEqualToString:@"00"]) { [cell.mySwitchButton setImage:[UIImage imageNamed:@"Switch-Off"] forState:UIControlStateNormal]; }else{ [cell.mySwitchButton setImage:[UIImage imageNamed:@"Switch-On"] forState:UIControlStateNormal]; } } if (indexPath.section==2&&indexPath.row==0) {//开关3 NSString*state=[backmodel.timer3 substringWithRange:NSMakeRange(2, 2)]; if ([state isEqualToString:@"00"]) { [cell.mySwitchButton setImage:[UIImage imageNamed:@"Switch-Off"] forState:UIControlStateNormal]; }else{ [cell.mySwitchButton setImage:[UIImage imageNamed:@"Switch-On"] forState:UIControlStateNormal]; } } if (indexPath.section==2&&indexPath.row==1) {//开关4 NSString*state=[backmodel.timer4 substringWithRange:NSMakeRange(2, 2)]; if ([state isEqualToString:@"00"]) { [cell.mySwitchButton setImage:[UIImage imageNamed:@"Switch-Off"] forState:UIControlStateNormal]; }else{ [cell.mySwitchButton setImage:[UIImage imageNamed:@"Switch-On"] forState:UIControlStateNormal]; } } if (indexPath.section==3&&indexPath.row==0) {//开关5 NSString*state=[backmodel.timer5 substringWithRange:NSMakeRange(2, 2)]; if ([state isEqualToString:@"00"]) { [cell.mySwitchButton setImage:[UIImage imageNamed:@"Switch-Off"] forState:UIControlStateNormal]; }else{ [cell.mySwitchButton setImage:[UIImage imageNamed:@"Switch-On"] forState:UIControlStateNormal]; } } if (indexPath.section==3&&indexPath.row==1) {//开关6 NSString*state=[backmodel.timer6 substringWithRange:NSMakeRange(2, 2)]; if ([state isEqualToString:@"00"]) { [cell.mySwitchButton setImage:[UIImage imageNamed:@"Switch-Off"] forState:UIControlStateNormal]; }else{ [cell.mySwitchButton setImage:[UIImage imageNamed:@"Switch-On"] forState:UIControlStateNormal]; } } } [cell setTuToSetCellBackAtIndex:indexPath]; //cell 选中效果 [cell.mySwitchButton addTarget:self action:@selector(btnCliCk:) forControlEvents:UIControlEventTouchUpInside]; return cell; } } } -(void)btnCliCk:(UIButton*)btn{ TimerSateModel*stateModel=[[TimerSateModel alloc]init]; stateModel.sendmacId = self.currentdevice.macAddress; stateModel.resavemacId = self.currentdevice.macAddress; stateModel.crc16String=@"0000"; XutoBackMsgModel *backmodel=[[DataCenter defaultDtacenter]valueForKey:@"xutoBackInfo"]; NSString*backState=nil; if (btn.tag==3010) { backState=[backmodel.timer1 substringWithRange:NSMakeRange(2, 2)]; stateModel.timerNumber=@"01"; }else if (btn.tag==3011){ backState=[backmodel.timer2 substringWithRange:NSMakeRange(2, 2)]; stateModel.timerNumber=@"02"; }else if (btn.tag==3020){ backState=[backmodel.timer3 substringWithRange:NSMakeRange(2, 2)]; stateModel.timerNumber=@"03"; // stateModel.timerState=[backmodel.timer3 substringWithRange:NSMakeRange(2, 2)]; }else if (btn.tag==3021){ backState=[backmodel.timer4 substringWithRange:NSMakeRange(2, 2)]; stateModel.timerNumber=@"04"; }else if (btn.tag==3030){ backState=[backmodel.timer5 substringWithRange:NSMakeRange(2, 2)]; stateModel.timerNumber=@"05"; }else if (btn.tag==3031){ backState=[backmodel.timer6 substringWithRange:NSMakeRange(2, 2)]; stateModel.timerNumber=@"06"; } if ([backState isEqualToString:@"01"]) { // mySwitchIsOn=YES; // }else{ // mySwitchIsOn=NO; stateModel.timerState=@"00";// 关 NSString*stateString=[NSString stringWithFormat:@"%@%@%@%@",stateModel.description,stateModel.timerNumber,stateModel.timerState,stateModel.crc16String]; NSData*selctorData=[dataContorl stringToHexData:stateString]; [[Socketsingleton sharedInstance] soketWriteData:selctorData]; [_indicatorView startAnimating]; [btn setImage:[UIImage imageNamed:@"Switch-Off"] forState:UIControlStateNormal]; }else{ stateModel.timerState=@"01";// 开 NSString*selectorString=[NSString stringWithFormat:@"%@%@%@%@",stateModel.description,stateModel.timerNumber,stateModel.timerState,stateModel.crc16String]; NSData*selctorData=[dataContorl stringToHexData:selectorString]; [[Socketsingleton sharedInstance] soketWriteData:selctorData]; [_indicatorView startAnimating]; [btn setImage:[UIImage imageNamed:@"Switch-On"] forState:UIControlStateNormal]; } } #pragma mark 开启关闭报警 -(void)xuTotempSwitchAction:(UIButton*)temperatureSwitch{ XutoBackMsgModel *backmodel=[[DataCenter defaultDtacenter]valueForKey:@"xutoBackInfo"]; setWaringTpModel*warModel1=[[setWaringTpModel alloc]init]; warModel1.sendmacId =self.currentdevice.macAddress; warModel1.resavemacId =self.currentdevice.macAddress; //BOOL isOn=[temperatureSwitch isOn]; if (temperatureSwitch.selected == YES) { NSLog(@"开"); temperatureSwitch.selected = NO; warModel1.kaiguan=@"01";// 开 warModel1.miniwaterTp=@"0000"; // 0 warModel1.maxwaterTp=@"0000";//0 }else{ temperatureSwitch.selected =YES; warModel1.kaiguan=@"00";// 关 warModel1.miniwaterTp=@"0000"; // 0 warModel1.maxwaterTp=@"0000";//0 NSLog(@"关"); } [self setTmperatureStateWithModel:warModel1 addBackModel:backmodel]; } -(void)setTmperatureStateWithModel:(setWaringTpModel*)waringModel addBackModel:(XutoBackMsgModel *)backModel{ NSString*maxminTpString=waringModel.description; waringModel.crc16Ing=@"0000"; NSString*minString=[NSString stringWithFormat:@"%@%@%@%@%@",maxminTpString,waringModel.kaiguan,waringModel.miniwaterTp,waringModel.maxwaterTp,waringModel.crc16Ing]; NSData*minwenDuData=[dataContorl stringToHexData:minString]; [[Socketsingleton sharedInstance] soketWriteData:minwenDuData]; [_indicatorView startAnimating]; backModel.miniTp=waringModel.miniwaterTp; backModel.maxTp=waringModel.maxwaterTp; } #pragma mark 换水提醒Action -(void)xuTochangeWaterSwitch:(UIButton*)sender{ UIButton*huanShuiSwitch=(UIButton*)sender; //BOOL isButtonOn=[huanShuiSwitch isOn]; NSUserDefaults*defuat=[NSUserDefaults standardUserDefaults]; NSString*picResult=[defuat valueForKey:@"xutopicResult"]; int pic = picResult.intValue; if (pic==0) { [self showTitle:@"" messsage:@"请设置提醒天数"]; if (huanShuiSwitch.selected == YES) { huanShuiSwitch.selected =NO; }else{ huanShuiSwitch.selected =YES; } }else{ if (huanShuiSwitch.selected ==YES) { //开 huanShuiSwitch.selected =NO; [IFISHHTTPTOOL setRemindWaterInfWith:self.currentdevice.deviceId waterRemind:@"1" remindCycle:picResult huishuiShiJian:^(setRemindWaterModel *remindModel) { self.nextChangeDateLabel=remindModel.remindDate; }]; //更新选择状态 设置界面 在不断 刷新 self.waterInfmodel.waterremind=@"1"; [self.tableView reloadData]; }else{ //关 huanShuiSwitch.selected =YES; [IFISHHTTPTOOL setRemindWaterInfWith:self.currentdevice.deviceId waterRemind:@"0" remindCycle:picResult huishuiShiJian:^(setRemindWaterModel *remindModel) { self.nextChangeDateLabel=remindModel.remindDate; self.waterInfmodel=remindModel; }]; self.waterInfmodel.waterremind=@"0"; [self.tableView reloadData]; } } } //-(void)returnBool:(ReturnBoolBlock)block{ // self.returnboolBlock=block; // //} #pragma mark tableView 头视图和脚视图 -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ if (section == 1) { return 50; }else if (section ==0){ return 5; }else { return 0; } } //-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ // // if (section==3) { // // return 50; // }else{ // return 0; // } //} -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section==0&&indexPath.row==2) { //ChangeWaterCell*cell=(ChangeWaterCell*)[self tableView:tableView cellForRowAtIndexPath:indexPath]; if (_huanShuiSwitchIsOn) { return 50; }else{ return 0; } }else if (indexPath.section==0&&indexPath.row==1){ if (![_currentdevice.waterRemind isEqual:[NSNull null]]) { return 50; }else{ return 0; } }else if (indexPath.section==0&&indexPath.row==0){ //会否有 预警 if (![_currentdevice.isPushWendu isEqual:[NSNull null]]) { if ([_currentdevice.isPushWendu isEqualToString:@"1"]) { return 50; }else{ return 0; } }else{ return 0; } }else{ return 50; } } //-(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ // NSString*str=@""; // if (section==1) { // str=@"灯1"; // }else if (section==2){ // // str=@"灯2"; // // }else if (section==3){ // // str=@"UV/冲浪"; // } // return str; //} -(void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section{ } -(void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section{ //view.alpha=0; } -(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ if (section==1) { UIImageView*secondSectionHeader=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"firstSetCell"]]; UILabel *label=[[UILabel alloc] init]; label.text=@"定时模式"; label.font = [UIFont systemFontOfSize:15]; label.frame=CGRectMake(18, 5, 100, 40); [secondSectionHeader addSubview:label]; return secondSectionHeader; }else if (section == 0){ UIView*oneHeader=[[UIView alloc] init]; oneHeader.backgroundColor=COLOR_MIAN; return oneHeader; }else{ return nil; } } //-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ // // if (section==3) { // // UIImageView*secondSectionHeader=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"secondSetCell"]]; // // return secondSectionHeader; // // } // return nil; //} #pragma mark tableView 点击事件 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ _indexpath=indexPath; if (indexPath.row==0&&indexPath.section==0) { _mypicView=[[MyPickerView alloc]init]; _mypicView.frame=CGRectMake(0, 0, kScreenSize.width, kScreenSize.height); [self.view.window addSubview:_mypicView]; [_mypicView.cancleButton addTarget:self action:@selector(mypicviewRemoveByCancle) forControlEvents:UIControlEventTouchUpInside]; [_mypicView.sureButton addTarget:self action:@selector(mypicViewRemoveByDone) forControlEvents:UIControlEventTouchUpInside]; [self temperatureMainQueue]; }else if (indexPath.section==0&&indexPath.row==1){ //换水提醒日期选择 _remindPic=[[remindCyclePic alloc]init]; _remindPic.frame=CGRectMake(0, 0, kScreenSize.width, kScreenSize.height); [self.view.window addSubview:_remindPic]; [_remindPic.cancleBtn addTarget:self action:@selector(xuToremindCyclePicRemove) forControlEvents:UIControlEventTouchUpInside]; [_remindPic.sureBtn addTarget:self action:@selector(xuToremindCyclePicDone) forControlEvents:UIControlEventTouchUpInside]; [self huanShuiMainQueue]; }else if (indexPath.section!=0){ _mydatepicView=[[MydatePickerView alloc]init]; _mydatepicView.frame=CGRectMake(0,0,kScreenSize.width,kScreenSize.height); [_mydatepicView.cancleButton addTarget:self action:@selector(cancleButtonClick) forControlEvents:UIControlEventTouchUpInside]; [_mydatepicView.sureButton addTarget:self action:@selector(doneButtonClick) forControlEvents:UIControlEventTouchUpInside]; XutoBackMsgModel *backmodel=[[DataCenter defaultDtacenter]valueForKey:@"xutoBackInfo"]; if (backmodel) { //在线 [self useMainQueue]; } // 设置pickerView 默认选择行 [self.view.window addSubview:_mydatepicView]; } } #pragma mark 移除换水时间选择器 -(void)xuToremindCyclePicRemove{ [_remindPic removeFromSuperview]; } #pragma mark 换水时间设置 -(void)xuToremindCyclePicDone{ if (_indexpath.section==0&&_indexpath.row==1) { ChangeWaterCell*cell=[self.tableView cellForRowAtIndexPath:_indexpath]; NSString *str=_remindPic.picViewResultString; if (str==nil) { //str=@"1"; NSLog(@"ni hua dong tai kuai"); str=[NSString stringWithFormat:@"%ld",(long)self.waterInfmodel.remindcycle]; [_remindPic makeToast:@"请设置换水天数"]; return; } cell.huanshuiDaylabel.text=[NSString stringWithFormat:@"%@天",str]; //设置换水日期 [IFISHHTTPTOOL setRemindWaterInfWith:self.currentdevice.deviceId waterRemind:@"1" remindCycle:str huishuiShiJian:^(setRemindWaterModel *remindModel) { self.nextChangeDateLabel=remindModel.remindDate; self.waterInfmodel.waterremind=@"1"; self.waterInfmodel.remindDate=remindModel.remindDate; self.waterInfmodel.remindcycle = remindModel.remindcycle; [self.tableView reloadData]; }]; NSUserDefaults*defuat=[NSUserDefaults standardUserDefaults]; [defuat setValue:str forKey:@"xutopicResult"]; [defuat synchronize]; [_remindPic removeFromSuperview]; } } #pragma mark 默认换水时间 -(void)huanShuiMainQueue{ if (_remindPic.picViewResultString !=nil || (_remindPic.picViewResultString ==nil && self.waterInfmodel.remindcycle !=0 )) { NSArray*shijianArr=[_remindPic.picArr objectAtIndex:0]; dispatch_async(_mainQueue, ^{ NSLog(@"a"); for (NSInteger k=0; k