ifish/Ifish/controllers/FishTinkController/maincontroller/CenterontrolControllers/RuSunTemp/RuSunTempNameViewController.m

160 lines
4.5 KiB
Objective-C

//
// RuSunTempNameViewController.m
// Ifish
//
// Created by imac on 2017/6/13.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import "RuSunTempNameViewController.h"
#import "UserExtendataArchaver.h"
#import "RunSunControlName.h"
#define RUSUNCHCELL_LIANGHT1 10000
#define RUSUNCHCELL_LIANGHT2 10001
#define RUSUNCHCELL_PUMP 10002
#define RUSUNCHCELL_HEAT 10003
#import "RuSunChangeNameTextViewCell.h"
@interface RuSunTempNameViewController ()
@end
@implementation RuSunTempNameViewController
- (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 4;
}
}
-(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==3&&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];
}
//自定义名字
RunSunControlName *ruSun = [UserExtendataArchaver currentRuSunTemp:self.device.macAddress];
if (indexPath.section==1&&indexPath.row==0) {
cell.chName.text = ruSun.light1;
}else if (indexPath.section==1&&indexPath.row==1){
cell.chName.text = ruSun.light2;
}else if (indexPath.section==1&&indexPath.row==2){
cell.chName.text = ruSun.pump;
}else if (indexPath.section==1&&indexPath.row==3){
cell.chName.text = ruSun.JiaRe;
}
cell.chName.delegate = self;
cell.tag = 10000 + indexPath.row;
return cell;
}
-(void)sureAction
{
//RunSunCHNameCustom 本地处理 保存按钮名称 不与服务器交互
RunSunControlName *ruSunch = [[RunSunControlName alloc] init];
RuSunChangeNameTextViewCell*cell1 = [self.view viewWithTag:RUSUNCHCELL_LIANGHT1];
if (cell1.chName.text.length>3) {
[self.view makeToast:@"灯1不能超过3个字"];
return;
}
if (cell1.chName.text.length==0) {
[self.view makeToast:@"灯1不能为空"];
return;
}
ruSunch.light1 = cell1.chName.text;
RuSunChangeNameTextViewCell*cell2 = [self.view viewWithTag:RUSUNCHCELL_LIANGHT2];
if (cell2.chName.text.length>3) {
[self.view makeToast:@"灯2不能超过3个字"];
return;
}
if (cell2.chName.text.length==0) {
[self.view makeToast:@"灯2不能为空"];
return;
}
ruSunch.light2 = cell2.chName.text;
RuSunChangeNameTextViewCell*cell3 = [self.view viewWithTag:RUSUNCHCELL_PUMP];
if (cell3.chName.text.length>3) {
[self.view makeToast:@"水泵名不能超过3个字"];
return;
}
if (cell3.chName.text.length==0) {
[self.view makeToast:@"水泵名不能为空"];
return;
}
ruSunch.pump = cell3.chName.text;
RuSunChangeNameTextViewCell*cell4 = [self.view viewWithTag:RUSUNCHCELL_HEAT];
if (cell4.chName.text.length>3) {
[self.view makeToast:@"加热棒名不能超过3个字"];
return;
}
if (cell4.chName.text.length==0) {
[self.view makeToast:@"加热棒名不能为空"];
return;
}
ruSunch.JiaRe = cell4.chName.text;
ruSunch.macAddress = self.device.macAddress;
[UserExtendataArchaver saveRuSunTmpname:ruSunch];
[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