// // EditLocationVC.m // Haishenghai-master // // Created by GG on 2019/1/20. // Copyright © 2019年 Haishenghai intelligence network technology. All rights reserved. // #import "EditLocationVC.h" #import "Header.h" #import @interface EditLocationVC () { UIButton *selectBtn; } @property(nonatomic,strong)UITextField *locationTF; @property(nonatomic,strong)UITextField *siteTF; @property(nonatomic,strong)NSMutableArray *dataArray; @property(nonatomic,strong)UITableView *tableView; @property(nonatomic,copy)NSString *selectID; @end @implementation EditLocationVC - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor whiteColor]; self.navigationItem.title = @"添加设备"; self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:60/255.0 green:114/255.0 blue:255/255.0 alpha:1]; [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}]; //设置导航栏左侧按钮 UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [backBtn setImage:[UIImage imageNamed:@"hsh_return"] forState:UIControlStateNormal]; backBtn.frame = CGRectMake(0, 0, 44, 44); [backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside]; backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn]; // JJOptionView *view1 = [[JJOptionView alloc] initWithFrame:CGRectMake(110, 190, WIDTH-130, 40)]; // view1.dataSource = @[@"1",@"2",@"3",@"4",@"5"]; // view1.delegate = self; // [self.view addSubview:view1]; [self setupUI]; [self showListView]; //查询场所 [DataSourceManager getSiteWithUrlPagesize:100 Page:1 completionBlock:^(NSMutableArray *array) { _dataArray = array; [_tableView reloadData]; }]; //键盘监听 // 添加通知监听见键盘弹出/退出 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardAction:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardAction:) name:UIKeyboardWillHideNotification object:nil]; } -(void)backClick{ [self.navigationController popViewControllerAnimated:YES]; } //- (void)optionView:(JJOptionView *)optionView selectedIndex:(NSInteger)selectedIndex { // NSLog(@"%@",optionView); // NSLog(@"%ld",selectedIndex); //} -(void)setupUI{ for (int i =0; i<4; i++) { NSArray *titleArray =@[@"设备编号:",@"设备名称:",@"安装位置:",@"所属场所:"]; UILabel *deveceLabel = [[UILabel alloc]init]; deveceLabel.text = [titleArray objectAtIndex:i]; deveceLabel.frame = CGRectMake(20+(100)*(i/4), kTopHeight+(40)*(i%4), 100, 40); deveceLabel.textAlignment = NSTextAlignmentLeft; deveceLabel.font = [UIFont systemFontOfSize:18]; deveceLabel.textColor = [UIColor blackColor]; [self.view addSubview:deveceLabel]; } for (int i =0; i<2; i++) { UILabel *detailLabel = [[UILabel alloc]init]; detailLabel.frame = CGRectMake(110+(200)*(i/2), kTopHeight+(40)*(i%2), WIDTH-130, 40); detailLabel.tag = i; if (i==0) { detailLabel.text = _deveceNumber; }else{ detailLabel.text = _deveceName; } detailLabel.textAlignment = NSTextAlignmentLeft; detailLabel.font = [UIFont systemFontOfSize:18]; detailLabel.textColor = [UIColor blackColor]; [self.view addSubview:detailLabel]; } _locationTF = [[UITextField alloc]init]; _locationTF.frame = CGRectMake(110, kTopHeight+80, WIDTH-130, 40); _locationTF.delegate = self; _locationTF.textAlignment = NSTextAlignmentLeft; _locationTF.font = [UIFont systemFontOfSize:18]; _locationTF.textColor = [UIColor blackColor]; [self.view addSubview:_locationTF]; _siteTF = [[UITextField alloc]init]; _siteTF.userInteractionEnabled =YES; _siteTF.frame = CGRectMake(110, kTopHeight+120, WIDTH-130, 40); _siteTF.textAlignment = NSTextAlignmentLeft; _siteTF.font = [UIFont systemFontOfSize:18]; _siteTF.delegate =self; _siteTF.textColor = [UIColor blackColor]; [self.view addSubview:_siteTF]; selectBtn = [UIButton buttonWithType:UIButtonTypeCustom]; selectBtn.frame = CGRectMake(_siteTF.frame.size.width-40, 0, 40, 40); [selectBtn setImage:[UIImage imageNamed:@"hsh_login_drop-up"] forState:UIControlStateNormal]; [selectBtn setImage:[UIImage imageNamed:@"hsh_login_drop-down"] forState:UIControlStateSelected]; [selectBtn addTarget:self action:@selector(selectedBtnClick:) forControlEvents:UIControlEventTouchUpInside]; [_siteTF addSubview:selectBtn]; for (int i =0; i<2; i++) { UIView *line = [[UIView alloc]init]; line.frame = CGRectMake(110+200*(i/2), (kTopHeight+119)+(39)*(i%2), WIDTH-130, 1); line.backgroundColor = [UIColor lightGrayColor]; [self.view addSubview:line]; } //提交按钮 /** 退出登录 */ UIButton *comitBtn = [UIButton buttonWithType:UIButtonTypeCustom]; comitBtn.frame = CGRectMake(20, HEIGHT-49-50, self.view.frame.size.width-40, 44); comitBtn.layer.cornerRadius = 18; [comitBtn setBackgroundImage:[UIImage imageNamed:@"blue"] forState:UIControlStateNormal]; [comitBtn setTitle:@"提交" forState:UIControlStateNormal]; [comitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; comitBtn.titleLabel.font = [UIFont systemFontOfSize:18]; comitBtn.titleLabel.textAlignment = NSTextAlignmentCenter; // self.loginButton.clipsToBounds = YES; [comitBtn addTarget:self action:@selector(comitBtnClick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:comitBtn]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)comitBtnClick{ NSLog(@"点击了%d",_typeID); NSString *inputText = [_locationTF.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; if (inputText.length==0) { ALERTSHOW(@"安装位置不能为空"); return; } NSString *str = [NSString stringWithFormat:@"%@",_deveceNumber]; [DataSourceManager addDeveceWithUrlDeveceID:_deveceNumber dLongtitude:@"120" dLatitude:@"120" dLocation:_locationTF.text siteid:_selectID completionBlock:^(NSDictionary *dic) { //导航栏返回特定视图 for (UIViewController *controller in self.navigationController.viewControllers) { if ([controller isKindOfClass:[ViewController class]]) { [self.navigationController popToViewController:controller animated:YES]; } } }]; } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self.view endEditing:YES]; } -(void)selectedBtnClick:(UIButton *)btn{ [_locationTF resignFirstResponder]; btn.selected =!btn.selected; if (btn.selected) { _tableView.hidden = NO; }else{ _tableView.hidden = YES; } } -(void)showListView{ _tableView = [[UITableView alloc]initWithFrame:CGRectMake(_siteTF.frame.origin.x, _siteTF.frame.origin.y+40, _siteTF.frame.size.width, 200) style:UITableViewStylePlain]; _tableView.delegate = self; _tableView.dataSource = self; _tableView.hidden =YES; [self.view addSubview:_tableView]; _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; self.tableView.layer.borderWidth = 1; self.tableView.layer.borderColor = [[UIColor lightGrayColor] CGColor];//设置列表边框 } #pragma mark---tableviewDelegate -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return _dataArray.count; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 40; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *cellId = @"cellID"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId]; if (!cell) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId]; } PlaceModel *place = self.dataArray[indexPath.row]; cell.textLabel.text =place.deployment; _selectID = place.Id; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; _siteTF.text = cell.textLabel.text; PlaceModel *place = self.dataArray[indexPath.row]; _selectID = place.Id; [_tableView removeFromSuperview]; } -(BOOL)textFieldShouldReturn:(UITextField *)textField{ [_locationTF resignFirstResponder]; return YES; } - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { if (textField ==_siteTF) { return NO; } return YES; } -(void)keyboardAction:(NSNotification *)sender{ NSString *nameStr = sender.name; //判断是哪个通知,做出相应的处理 //键盘弹出 if ([nameStr isEqualToString:UIKeyboardWillShowNotification]) { _tableView.hidden =YES; selectBtn.selected = NO; } } /* #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