ifish/Ifish/controllers/FishTinkController/maincontroller/CenterontrolControllers/ThreeControl/ThreeControlNameViewControl...

148 lines
4.1 KiB
Objective-C

//
// ThreeControlNameViewController.m
// Ifish
//
// Created by imac on 2017/6/15.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import "ThreeControlNameViewController.h"
#import "RuSunChangeNameTextViewCell.h"
#import "ThreeControlName.h"
#import "UserExtendataArchaver.h"
#define THREECHCELL_LIANGHT1 30000
#define THREECHCELL_LIANGHT2 30001
#define THREECHCELL_PUMP 30002
@interface ThreeControlNameViewController ()
@end
@implementation ThreeControlNameViewController
- (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 3;
}
}
-(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==2&&indexPath.section==1) {
cell.lineImgView.image = [UIImage imageNamed:@"redact_line_last"];
}
NSArray *titles= @[@"灯1",@"灯2",@"UV/冲浪"];
if (indexPath.section==1) {
cell.chTitle.text = titles[indexPath.row];
}
//自定义名字
ThreeControlName *name = [UserExtendataArchaver currentThreeControlName:self.device.macAddress];
if (indexPath.section==1&&indexPath.row==0) {
cell.chName.text = name.light1Name;
}else if (indexPath.section==1&&indexPath.row==1){
cell.chName.text = name.light2Name;
}else if (indexPath.section==1&&indexPath.row==2){
cell.chName.text = name.pumpName;
}
cell.chName.delegate = self;
cell.tag = 30000 + indexPath.row;
return cell;
}
-(void)sureAction
{
//RunSunCHNameCustom 本地处理 保存按钮名称 不与服务器交互
ThreeControlName *name = [[ThreeControlName alloc] init];
RuSunChangeNameTextViewCell*cell1 = [self.view viewWithTag:THREECHCELL_LIANGHT1];
if (cell1.chName.text.length>3) {
[self.view makeToast:@"灯1不能超过3个字"];
return;
}
if (cell1.chName.text.length==0) {
[self.view makeToast:@"灯1不能为空"];
return;
}
name.light1Name = cell1.chName.text;
RuSunChangeNameTextViewCell*cell2 = [self.view viewWithTag:THREECHCELL_LIANGHT2];
if (cell2.chName.text.length>3) {
[self.view makeToast:@"灯2不能超过3个字"];
return;
}
if (cell2.chName.text.length==0) {
[self.view makeToast:@"灯2不能为空"];
return;
}
name.light2Name = cell2.chName.text;
RuSunChangeNameTextViewCell*cell3 = [self.view viewWithTag:THREECHCELL_PUMP];
if (cell3.chName.text.length>3) {
[self.view makeToast:@"水泵不能超过3个字"];
return;
}
if (cell3.chName.text.length==0) {
[self.view makeToast:@"水泵不能为空"];
return;
}
name.pumpName = cell3.chName.text;
name.macAddress = self.device.macAddress;
[UserExtendataArchaver saveThreeControlName: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