单军华
2018-03-28 f99cf1d5cc50407394501853be06cb39f38a092c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//
//  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 ()<UITextFieldDelegate>
{
    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