ThingsAddViewController.m 4.4 KB

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