92 lines
3.2 KiB
Objective-C
92 lines
3.2 KiB
Objective-C
//
|
|
// IfishHotBarModifyNameVc.m
|
|
// Ifish
|
|
//
|
|
// Created by 罗艺 on 2018/9/25.
|
|
// Copyright © 2018年 lianlian. All rights reserved.
|
|
//
|
|
|
|
#import "IfishHotBarModifyNameVc.h"
|
|
|
|
@interface IfishHotBarModifyNameVc ()
|
|
@property (weak, nonatomic) IBOutlet UITextField *nameTextF;
|
|
|
|
@end
|
|
|
|
@implementation IfishHotBarModifyNameVc
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
// Do any additional setup after loading the view from its nib.
|
|
self.title=@"修改名称";
|
|
self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"保存" style:0 target:self action:@selector(clickModifyName)];
|
|
UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
back.frame = CGRectMake(0,0,48,44);
|
|
[back setImage:[UIImage imageNamed:@"back_btn"] forState:UIControlStateNormal];
|
|
// [_bakbutton setBackgroundImage:[UIImage imageNamed:@"back_btn"] forState:UIControlStateNormal];
|
|
|
|
[back addTarget: self action: @selector(clickBack) forControlEvents: UIControlEventTouchUpInside];
|
|
[back setContentEdgeInsets:UIEdgeInsetsMake(0, 10, 0, -10)];
|
|
back.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
|
|
UIBarButtonItem * backItem=[[UIBarButtonItem alloc] initWithCustomView:back];
|
|
|
|
self.navigationItem.leftBarButtonItem=backItem;
|
|
}
|
|
|
|
-(void)clickBack{
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
}
|
|
|
|
-(void)viewWillAppear:(BOOL)animated{
|
|
[super viewWillAppear:animated];
|
|
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault];
|
|
}
|
|
|
|
- (void)clickModifyName{
|
|
[self modifyNameWith:self.nameTextF.text];
|
|
}
|
|
|
|
|
|
-(void)modifyNameWith:(NSString*)str{
|
|
// priId.deviceId Integer 是 设备ID
|
|
// priId.userId Integer 是 用户ID
|
|
// showName string 是 显示名称
|
|
|
|
|
|
NSDictionary*para=@{
|
|
@"priId.deviceId":self.devicemodel.deviceId,
|
|
@"priId.userId":self.devicemodel.userId,
|
|
@"showName":str
|
|
};
|
|
[AFHttpTool requestWihtMethod:RequestMethodTypePost url:kUpdateDeviceUser params:para success:^(id response) {
|
|
NSLog(@"-----------%@",response);
|
|
NSDictionary*dict=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
|
|
NSString*result=dict[@"result"];
|
|
if ([result integerValue]==100) {
|
|
// self.vo=[IfishHotBarVo mj_objectWithKeyValues:dict[@"data"]];
|
|
[self.view makeToast:@"修改成功"];
|
|
[[NSUserDefaults standardUserDefaults]setObject:str forKey:@"dTitle"];
|
|
[self updateNameInLocalWithName:str];
|
|
}
|
|
} failure:^(NSError *err) {
|
|
[self.view makeToast:@"修改失败"];
|
|
}];
|
|
}
|
|
|
|
|
|
-(void)updateNameInLocalWithName:(NSString*)name{
|
|
NSArray* deviceArr =[dataContorl getallDevices];
|
|
for (DeviceModel *device in deviceArr) {
|
|
if (device.deviceId==self.devicemodel.deviceId) {
|
|
device.showName=name;
|
|
[[DataCenter defaultDtacenter]setValue:deviceArr forKey:@"deviceInfo"];
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"updateDevice" object:nil];
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
@end
|