DeviceInfoEditViewController.mm 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //
  2. // DeviceInfoEditViewController.m
  3. // FunSDKDemo
  4. //
  5. // Created by wujiangbo on 2018/11/19.
  6. // Copyright © 2018年 wujiangbo. All rights reserved.
  7. //
  8. #import "DeviceInfoEditViewController.h"
  9. #import "DeviceManager.h"
  10. #import "AddDeviceInputCell.h"
  11. #import <Masonry/Masonry.h>
  12. @interface DeviceInfoEditViewController ()<UITableViewDelegate,UITableViewDataSource,DeviceManagerDelegate>
  13. {
  14. NSArray *titleArray; //列表数组
  15. DeviceManager *deviceManager; //设备管理器
  16. UITextField *devNameTF; //设备名
  17. UITextField *devPswTF; //设备密码
  18. UITextField *serialTF; //设备序列号
  19. UITextField *userNameTF; //用户名
  20. }
  21. @property (nonatomic,strong)UITableView *listTableView; //输入列表
  22. @property (nonatomic,strong)UIButton *editBtn; //添加按钮
  23. @end
  24. @implementation DeviceInfoEditViewController
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. self.view.backgroundColor = [UIColor whiteColor];
  28. //设备管理器
  29. deviceManager = [[DeviceManager alloc] init];
  30. deviceManager.delegate = self;
  31. //设置导航栏
  32. [self setNaviStyle];
  33. //初始化数据
  34. [self initDataSource];
  35. [self.view addSubview:self.listTableView];
  36. [self.view addSubview:self.editBtn];
  37. //控件布局
  38. [self configSubView];
  39. }
  40. - (void)setNaviStyle {
  41. self.navigationItem.title = TS("");
  42. UIBarButtonItem *leftBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"new_back.png"] style:UIBarButtonItemStylePlain target:self action:@selector(popViewController)];
  43. self.navigationItem.leftBarButtonItem = leftBtn;
  44. }
  45. #pragma mark - 控件布局
  46. -(void)configSubView{
  47. [self.listTableView mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.top.equalTo(@110);
  49. make.width.equalTo(self.view.mas_width).multipliedBy(0.9);
  50. make.height.equalTo(@200);
  51. make.centerX.equalTo(self.view.mas_centerX);
  52. }];
  53. [self.editBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.top.equalTo(self.listTableView.mas_bottom).offset(50);
  55. make.width.equalTo(self.view.mas_width).multipliedBy(0.9);
  56. make.height.equalTo(@45);
  57. make.centerX.equalTo(self.view);
  58. }];
  59. }
  60. #pragma mark - button event
  61. -(void)popViewController{
  62. [self.navigationController popViewControllerAnimated:YES];
  63. }
  64. -(void)editBtnClicked{
  65. //修改设备名称和设备密码
  66. [SVProgressHUD show];
  67. [deviceManager changeDevice:serialTF.text devName:devNameTF.text username:userNameTF.text password:devPswTF.text];
  68. }
  69. #pragma mark 点击空白处关闭键盘
  70. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  71. [self.view endEditing:YES];
  72. }
  73. #pragma mark - tableViewDataSource/Delegate
  74. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  75. return titleArray.count;
  76. }
  77. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  78. return 50;
  79. }
  80. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  81. AddDeviceInputCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AddDeviceInputCell"];
  82. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  83. NSString *titleStr = titleArray[indexPath.row];
  84. cell.customTitle.text = titleStr;
  85. if ([titleStr isEqualToString:TS("Device_Name")]) {
  86. cell.inputTextField.attributedPlaceholder =
  87. [[NSAttributedString alloc]initWithString:TS("Enter_Device_Name") attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]}];
  88. cell.inputTextField.text = self.devObject.deviceName;
  89. devNameTF = cell.inputTextField;
  90. }
  91. else if ([titleStr isEqualToString:TS("serial_number")]){
  92. cell.inputTextField.attributedPlaceholder =
  93. [[NSAttributedString alloc]initWithString:TS("Enter_serial_number") attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]}];
  94. cell.inputTextField.text = self.devObject.deviceMac;
  95. cell.inputTextField.enabled = NO;
  96. serialTF = cell.inputTextField;
  97. }
  98. else if ([titleStr isEqualToString:TS("UserName")]){
  99. cell.inputTextField.attributedPlaceholder =
  100. [[NSAttributedString alloc]initWithString:TS("Enter_LoginName") attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]}];
  101. cell.inputTextField.text = self.devObject.loginName;
  102. cell.inputTextField.enabled = NO;
  103. userNameTF = cell.inputTextField;
  104. }
  105. else if ([titleStr isEqualToString:TS("Password2")]){
  106. cell.inputTextField.attributedPlaceholder =
  107. [[NSAttributedString alloc]initWithString:TS("Enter_LoginPassword") attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]}];
  108. cell.inputTextField.text = self.devObject.loginPsw;
  109. devPswTF = cell.inputTextField;
  110. }
  111. return cell;
  112. }
  113. #pragma mark - funsdk 回调处理
  114. // 修改设备信息结果
  115. - (void)changeDevice:(NSString *)sId changedResult:(int)result{
  116. if (result >= 0) {
  117. [SVProgressHUD showSuccessWithStatus:TS("Success")];
  118. if (self.editSuccess) {
  119. self.editSuccess();
  120. }
  121. [self.navigationController popViewControllerAnimated:YES];
  122. }
  123. else{
  124. [MessageUI ShowErrorInt:result];
  125. }
  126. }
  127. #pragma mark - 界面和数据初始化
  128. - (void)initDataSource {
  129. titleArray = @[TS("Device_Name"),TS("serial_number"),TS("UserName"),TS("Password2")];
  130. }
  131. -(UITableView *)listTableView{
  132. if (!_listTableView) {
  133. _listTableView = [[UITableView alloc] init];
  134. _listTableView.delegate = self;
  135. _listTableView.dataSource = self;
  136. _listTableView.scrollEnabled = NO;
  137. [_listTableView registerClass:[AddDeviceInputCell class] forCellReuseIdentifier:@"AddDeviceInputCell"];
  138. }
  139. return _listTableView;
  140. }
  141. -(UIButton *)editBtn{
  142. if (!_editBtn) {
  143. _editBtn = [[UIButton alloc] init];
  144. [_editBtn addTarget:self action:@selector(editBtnClicked) forControlEvents:UIControlEventTouchUpInside];
  145. [_editBtn setTitle:TS("OK") forState:UIControlStateNormal];
  146. [_editBtn setBackgroundColor:GlobalMainColor];
  147. }
  148. return _editBtn;
  149. }
  150. @end