BuzzerViewController.mm 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // BuzzerViewController.m
  3. // FunSDKDemo
  4. //
  5. // Created by Levi on 2019/1/4.
  6. // Copyright © 2019年 Levi. All rights reserved.
  7. //
  8. #import "BuzzerConfig.h"
  9. #import "BuzzerViewController.h"
  10. #import "Header.h"
  11. @interface BuzzerViewController ()<BuzzerConfigDelegate,UITableViewDelegate,UITableViewDataSource>{
  12. BuzzerConfig *config;
  13. }
  14. @property (nonatomic, strong) UITableView *myTableView;
  15. @property (nonatomic, strong) UISwitch *mySwitch;
  16. @property (nonatomic, assign) BOOL alarmBellState;
  17. @end
  18. @implementation BuzzerViewController
  19. #pragma mark -- LazyLoad
  20. -(UITableView *)myTableView{
  21. if (!_myTableView) {
  22. _myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) style:UITableViewStylePlain];
  23. _myTableView.delegate = self;
  24. _myTableView.dataSource = self;
  25. _myTableView.backgroundColor = [UIColor colorWithRed:234.0/255.0 green:234.0/255.0 blue:234.0/255.0 alpha:1];
  26. [_myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"myCell"];
  27. _myTableView.tableFooterView = [UIView new];
  28. }
  29. return _myTableView;
  30. }
  31. -(UISwitch *)mySwitch{
  32. if (!_mySwitch) {
  33. _mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 50, 30)];
  34. [_mySwitch addTarget:self action:@selector(transformAlarmBellState:) forControlEvents:UIControlEventValueChanged];
  35. }
  36. return _mySwitch;
  37. }
  38. - (void)viewDidLoad {
  39. [super viewDidLoad];
  40. [self initData];
  41. [self configSubViews];
  42. [self getBuzzerConfig];
  43. }
  44. #pragma mark -- alarmBellState default NO
  45. -(void)initData{
  46. self.alarmBellState = NO;
  47. }
  48. -(void)configSubViews{
  49. [self.view addSubview:self.myTableView];
  50. }
  51. #pragma mark --getConfigAboutDeviceBuzzerState
  52. -(void)getBuzzerConfig{
  53. [SVProgressHUD showWithStatus:TS("")];
  54. if (config == nil) {
  55. config = [[BuzzerConfig alloc] init];
  56. config.delegate = self;
  57. }
  58. [config getDeviceBuzzerAlarmConfig];
  59. }
  60. #pragma mark --getConfigAboutDeviceBuzzerStateResult
  61. -(void)getDeviceBuzzerAlarmConfigResult:(BOOL)AlarmBellState{
  62. self.alarmBellState = AlarmBellState;
  63. [self.myTableView reloadData];
  64. }
  65. #pragma mark --setConfigAboutDeviceBuzzerStateResult
  66. - (void)setDeviceBuzzerAlarmConfigResult:(int)result{
  67. if (result <0) {
  68. [MessageUI ShowErrorInt:result];
  69. }else{
  70. [SVProgressHUD showSuccessWithStatus:TS("config_Save_Success") duration:1.5f];
  71. }
  72. }
  73. #pragma mark -- UITableViewDelegate/DataSource
  74. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  75. return 1;
  76. }
  77. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  78. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myCell"];
  79. cell.textLabel.text = TS("Buzzer_setting");
  80. cell.accessoryView = self.mySwitch;
  81. self.mySwitch.on = self.alarmBellState;
  82. return cell;
  83. }
  84. -(void)transformAlarmBellState:(UISwitch *)sender{
  85. [config setDeviceBuzzerAlarmConfig:sender.on];
  86. }
  87. @end