HomeHubSearchSuccessViewController.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // HomeHubSearchSuccessViewController.m
  3. // OneCable
  4. //
  5. // Created by nComz on 2017. 5. 11..
  6. // Copyright © 2017년 ntels. All rights reserved.
  7. //
  8. #import "HomeHubSearchSuccessViewController.h"
  9. #import "CustomTableView.h"
  10. #import "CustomCheckBox.h"
  11. #import "HomeHubConnectWifiViewController.h"
  12. @interface HomeHubSearchSuccessViewController ()<CustomCheckBoxDelegate> {
  13. BLEServiceHandler *bleService;
  14. NSMutableArray *devices;
  15. NSArray *_tableZombieValues;
  16. BTLEDeivceModel *selectedModel;
  17. }
  18. @end
  19. @implementation HomeHubSearchTableViewCell
  20. @end
  21. @implementation HomeHubSearchSuccessViewController
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. [self initUI];
  25. [self prepareViewDidLoad];
  26. }
  27. - (void)didReceiveMemoryWarning {
  28. [super didReceiveMemoryWarning];
  29. }
  30. - (void)viewWillAppear:(BOOL)animated{
  31. [super viewWillAppear:animated];
  32. bleService.delegate = self;
  33. }
  34. - (void)viewWillDisappear:(BOOL)animated {
  35. [super viewWillDisappear:animated];
  36. bleService.delegate = nil;
  37. }
  38. - (void)initUI {
  39. _btnNext.enabled = NO;
  40. [self initTableViewAsDefaultStyle:_tableView];
  41. }
  42. - (void)prepareViewDidLoad {
  43. //ble
  44. bleService = [BLEServiceHandler sharedManager];
  45. devices = [bleService getDeviceList];
  46. [_tableView reloadData];
  47. }
  48. #pragma mark - UITableView DataSource & Delegate
  49. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  50. return 1;
  51. }
  52. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  53. return devices.count;
  54. }
  55. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  56. return 108.0f;
  57. }
  58. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  59. HomeHubSearchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HubSearchCellIdentifier"];
  60. BTLEDeivceModel *bleModel = [devices objectAtIndex:indexPath.row];
  61. cell.lblHubName.text = bleModel.peripheralRef.name;
  62. cell.lblSerialNum.text = [NSString stringWithFormat:@"S/N : %@",bleModel.peripheralRef.identifier];
  63. cell.chkBtn.selected = [selectedModel isEqual:bleModel];
  64. return cell;
  65. }
  66. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  67. [super tableView:tableView didSelectRowAtIndexPath:indexPath];
  68. selectedModel = [devices objectAtIndex:indexPath.row];
  69. _btnNext.enabled = YES;
  70. [tableView reloadData];
  71. }
  72. #pragma mark - User Event
  73. - (IBAction)btnNextTouched:(id)sender {
  74. NSLog(@"selectedModel : %@", selectedModel);
  75. if (selectedModel != nil) {
  76. [bleService setConDevice:selectedModel];
  77. HomeHubConnectWifiViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"HomeHubConnectWifiViewController" storyboardName:@"HomeHub"];
  78. [self.navigationController pushViewController:vc animated:YES];
  79. }
  80. }
  81. - (IBAction)btnCloseTouched:(id)sender {
  82. [self.navigationController popToRootViewControllerAnimated:YES];
  83. }
  84. @end