ThingsAddViewController.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //
  2. // ThingsAddViewController.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 5/8/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "RequestHandler.h"
  10. #import "DeviceModel.h"
  11. #import "CustomLabel.h"
  12. #import "CustomButton.h"
  13. #import "CustomImageView.h"
  14. #import "ThingsAddWallpadSubViewController.h"
  15. #import "ThingsAddViewController.h"
  16. #import "ThingsAddStartViewController.h"
  17. @implementation ThingsAddTableViewCell
  18. @end
  19. @interface ThingsAddViewController () <UITableViewDataSource, UITableViewDelegate> {
  20. NSArray *_addableDeviceList;
  21. }
  22. @end
  23. #pragma mark - Class Definition
  24. @implementation ThingsAddViewController
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. // Do any additional setup after loading the view.
  28. [self initUI];
  29. [self prepareViewDidLoad];
  30. }
  31. - (void)viewWillAppear:(BOOL)animated {
  32. [super viewWillAppear:animated];
  33. }
  34. - (void)initUI {
  35. [self initTableViewAsDefaultStyle:_tableView];
  36. }
  37. - (void)prepareViewDidLoad {
  38. _addableDeviceList = @[@{@"deviceName" : @"다원 스마트 플러그",
  39. @"manufacturer" : @"다원",
  40. @"nodeName" : @"스마트 플러그",
  41. @"deviceKey": @"DAOWN"},
  42. @{@"deviceName" : @"다우앤텍 멀티 센서",
  43. @"manufacturer" : @"다우엔텍",
  44. @"nodeName" : @"멀티센서",
  45. @"deviceKey": @"DAWOO"}];
  46. }
  47. #pragma mark - Main Logic
  48. #pragma mark - UITableView DataSource & Delegate
  49. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  50. return _addableDeviceList.count;
  51. }
  52. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  53. CGFloat height = 220;
  54. return height;
  55. }
  56. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  57. ThingsAddTableViewCell *cell = (ThingsAddTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"AddCellIdentifier"];
  58. NSDictionary *addableDevice = _addableDeviceList[indexPath.row];
  59. cell.lblDeviceName.text = addableDevice[@"deviceName"];
  60. cell.lblVendor.text = addableDevice[@"manufacturer"];
  61. // if (![cell.btnAdd actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  62. // [cell.btnAdd addTarget:self action:@selector(btnAddDeviceTouched:) forControlEvents:UIControlEventTouchUpInside];
  63. // }
  64. return cell;
  65. }
  66. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  67. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  68. NSDictionary *addableDevice = _addableDeviceList[indexPath.row];
  69. ThingsAddStartViewController *vc = (ThingsAddStartViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"ThingsAddStartViewController" storyboardName:@"Things"];
  70. vc.addableDevice = addableDevice;
  71. vc.providesPresentationContextTransitionStyle = YES;
  72. vc.definesPresentationContext = YES;
  73. [vc setModalPresentationStyle:UIModalPresentationOverCurrentContext];
  74. [self presentViewController:vc animated:NO completion:nil];
  75. }
  76. #pragma mark - TableView Delegate
  77. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  78. // Remove seperator inset
  79. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  80. [cell setSeparatorInset:UIEdgeInsetsZero];
  81. }
  82. // Prevent the cell from inheriting the Table View's margin settings
  83. if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
  84. [cell setPreservesSuperviewLayoutMargins:NO];
  85. }
  86. // Explictly set your cell's layout margins
  87. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  88. [cell setLayoutMargins:UIEdgeInsetsZero];
  89. }
  90. }
  91. #pragma mark - UI Events
  92. - (void)btnAddDeviceTouched:(id)sender {
  93. }
  94. - (IBAction)btnCloseTouched:(id)sender {
  95. [self dismissViewControllerAnimated:YES completion:nil];
  96. }
  97. #pragma mark - MemoryWarning
  98. - (void)didReceiveMemoryWarning
  99. {
  100. [super didReceiveMemoryWarning];
  101. // Dispose of any resources that can be recreated.
  102. }
  103. @end