ifish/Ifish/controllers/FishTinkController/maincontroller/CenterontrolControllers/SongNuo/SongNuo86Byte/SongNuo86NameViewController.m

189 lines
5.5 KiB
Objective-C

//
// SongNuo86NameViewController.m
// Ifish
//
// Created by imac on 2017/6/14.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import "SongNuo86NameViewController.h"
#import "RuSunChangeNameTextViewCell.h"
#import "SongNuo86Name.h"
#import "UserExtendataArchaver.h"
#define SONG86CELL_LIANGHT1 11000
#define SONG86CELL_LIANGHT2 11001
#define SONG86CELL_WP 11002
#define SONG86CELL_AP 11003
#define SONG86CELL_GD 11004
#define SONG86CELL_JR 11005
@interface SongNuo86NameViewController ()
@end
@implementation SongNuo86NameViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.tableView.dataSource = self;
}
-(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];
}
//自定义名字
SongNuo86Name *name = [UserExtendataArchaver currentSongNuo86:self.device.macAddress];
if (indexPath.section==1&&indexPath.row==0) {
cell.chName.text = name.light1;
}else if (indexPath.section==1&&indexPath.row==1){
cell.chName.text = name.light2;
}else if (indexPath.section==1&&indexPath.row==2){
cell.chName.text = name.waterPump;
}else if (indexPath.section==1&&indexPath.row==3){
cell.chName.text = name.airPump;
}
else if (indexPath.section==1&&indexPath.row==4){
cell.chName.text = name.guideng;
}
else if (indexPath.section==1&&indexPath.row==5){
cell.chName.text = name.jiaRe;
}
cell.chName.delegate = self;
cell.tag = 11000 + indexPath.row;
return cell;
}
-(void)sureAction
{
//RunSunCHNameCustom 本地处理 保存按钮名称 不与服务器交互
SongNuo86Name *songN = [[SongNuo86Name alloc] init];
RuSunChangeNameTextViewCell*cell1 = [self.view viewWithTag:SONG86CELL_LIANGHT1];
if (cell1.chName.text.length>3) {
[self.view makeToast:@"灯1不能超过3个字"];
return;
}
if (cell1.chName.text.length==0) {
[self.view makeToast:@"灯1不能为空"];
return;
}
songN.light1 = cell1.chName.text;
RuSunChangeNameTextViewCell*cell2 = [self.view viewWithTag:SONG86CELL_LIANGHT2];
if (cell2.chName.text.length>3) {
[self.view makeToast:@"灯2不能超过3个字"];
return;
}
if (cell2.chName.text.length==0) {
[self.view makeToast:@"灯2不能为空"];
return;
}
songN.light2 = cell2.chName.text;
RuSunChangeNameTextViewCell*cell3 = [self.view viewWithTag:SONG86CELL_WP];
if (cell3.chName.text.length>3) {
[self.view makeToast:@"水泵名不能超过3个字"];
return;
}
if (cell3.chName.text.length==0) {
[self.view makeToast:@"水泵名不能为空"];
return;
}
songN.waterPump = cell3.chName.text;
RuSunChangeNameTextViewCell*cell4 = [self.view viewWithTag:SONG86CELL_AP];
if (cell4.chName.text.length>3) {
[self.view makeToast:@"氧泵名不能超过3个字"];
return;
}
if (cell4.chName.text.length==0) {
[self.view makeToast:@"氧泵名不能为空"];
return;
}
songN.airPump = cell4.chName.text;
RuSunChangeNameTextViewCell*cell5 = [self.view viewWithTag:SONG86CELL_GD];
if (cell5.chName.text.length>3) {
[self.view makeToast:@"柜灯名不能超过3个字"];
return;
}
if (cell5.chName.text.length==0) {
[self.view makeToast:@"柜灯名不能为空"];
return;
}
songN.guideng = cell5.chName.text;
RuSunChangeNameTextViewCell*cell6 = [self.view viewWithTag:SONG86CELL_JR];
if (cell6.chName.text.length>3) {
[self.view makeToast:@"加热棒名不能超过3个字"];
return;
}
if (cell6.chName.text.length==0) {
[self.view makeToast:@"加热棒名不能为空"];
return;
}
songN.jiaRe = cell6.chName.text;
songN.macAddress = self.device.macAddress;
[UserExtendataArchaver saveSongNuo86Name: songN];
[self upLoadDeviceName];
}
- (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