// // ChangeDeviceNamePage.m // airtree // // Created by WindShan on 2016/11/18. // Copyright © 2016年 Gloria. All rights reserved. // #import "ChangeDeviceNamePage.h" #import "CommonReqModel.h" #import "NetworkSingleton.h" @interface ChangeDeviceNamePage () { UITextField * deviceNameTextField; UIButton * resetDeviceNameBtn; } @end @implementation ChangeDeviceNamePage - (void)viewDidLoad { [super viewDidLoad]; self.title = @"更新设备名称"; [self setNavigationLeft:@"返回" sel:@selector(backAction)]; deviceNameTextField = [[UITextField alloc] initWithFrame:CGRectMake(30, 40, SCREEN_WIDTH-60, 35)]; deviceNameTextField.secureTextEntry = NO; deviceNameTextField.placeholder = @"请输入新的名称"; deviceNameTextField.font = [UIFont fontWithName:@"Arial" size:16]; deviceNameTextField.delegate = self; deviceNameTextField.layer.borderColor = [RgbColor(213, 213, 213) CGColor]; deviceNameTextField.layer.masksToBounds=YES; deviceNameTextField.layer.cornerRadius=5.0f; deviceNameTextField.layer.borderWidth= 1.0f; deviceNameTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; // 设置一个空白blankView,15.0就是这块View的宽度width,也是光标的位置,根据你自己的需要设定大小 deviceNameTextField.leftView = [[UIView alloc] initWithFrame:CGRectMake(deviceNameTextField.frame.origin.x,deviceNameTextField.frame.origin.y,10.0, deviceNameTextField.frame.size.height)]; deviceNameTextField.leftViewMode =UITextFieldViewModeAlways; [self.view addSubview:deviceNameTextField]; deviceNameTextField.text = self.currentModel.name; //[deviceNameTextField setText:_selectedDevice.name]; resetDeviceNameBtn = [UIButton buttonWithType:UIButtonTypeCustom]; resetDeviceNameBtn.frame = CGRectMake(30,90, SCREEN_WIDTH-60, 40); [resetDeviceNameBtn setBackgroundImage:[UIImage imageNamed:@"login_btn_bk" ] forState:UIControlStateNormal]; [resetDeviceNameBtn setTitle:@"提 交" forState:UIControlStateNormal]; resetDeviceNameBtn.titleLabel.font = [UIFont systemFontOfSize: 18.0]; [resetDeviceNameBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; resetDeviceNameBtn.layer.masksToBounds=YES; resetDeviceNameBtn.layer.cornerRadius=5.0f; [resetDeviceNameBtn addTarget:self action:@selector(resetDeviceNameAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:resetDeviceNameBtn]; } -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:YES]; self.navigationController.navigationBarHidden = NO; } -(void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:YES]; resetDeviceNameBtn.userInteractionEnabled = YES; resetDeviceNameBtn.alpha = 1; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark button event begin -(void)backAction { [self dismissViewControllerAnimated:YES completion:nil]; } -(void)resetDeviceNameAction { if(deviceNameTextField.text.length == 0) { [Global alertMessageEx:@"请输入设备名称." title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; } else { //_loginUser[@"_id"], _selectedDevice[@"_id"] NSString *path = [NSString stringWithFormat:UPDATE_SPARE]; NSMutableDictionary * params = [[NSMutableDictionary alloc] init]; [params setObject:self.currentModel._id forKey:@"spare_id"]; [params setObject:deviceNameTextField.text forKey:@"name"]; [params setObject:[NSString stringWithFormat:@"%d",self.currentModel.status] forKey:@"status"]; MPWeakSelf(self); [NetworkSingleton networkingPostMethod:params urlName:path success:^(id responseBody) { BaseResModel * resModel = [Global toBaseModel:responseBody]; if(resModel.code == 0) { [Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; } else { [Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; } } failure:^(NSString *error) { LOG_INFO(@"失败:%@",error); [Global alertMessageEx:error title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; }]; } } #pragma mark button event end #pragma mark disappear keyboard begin -(BOOL)textFieldShouldReturn:(UITextField *)textField { if ([textField isFirstResponder]) { [textField resignFirstResponder]; } return true; } -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [self textFieldShouldReturn:deviceNameTextField]; } #pragma mark disappear keyboard end /* #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