ThingsAddViewController.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 = 154.0f;
  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. NSLog(@"들어옴");
  70. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  71. NSDictionary *addableDevice = _addableDeviceList[indexPath.row];
  72. ThingsAddStartViewController *vc = (ThingsAddStartViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"ThingsAddStartViewController" storyboardName:@"Things"];
  73. vc.addableDevice = addableDevice;
  74. vc.providesPresentationContextTransitionStyle = YES;
  75. vc.definesPresentationContext = YES;
  76. [vc setModalPresentationStyle:UIModalPresentationOverCurrentContext];
  77. [self presentViewController:vc animated:NO completion:nil];
  78. }
  79. #pragma mark - TableView Delegate
  80. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  81. // Remove seperator inset
  82. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  83. [cell setSeparatorInset:UIEdgeInsetsZero];
  84. }
  85. // Prevent the cell from inheriting the Table View's margin settings
  86. if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
  87. [cell setPreservesSuperviewLayoutMargins:NO];
  88. }
  89. // Explictly set your cell's layout margins
  90. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  91. [cell setLayoutMargins:UIEdgeInsetsZero];
  92. }
  93. }
  94. #pragma mark - UI Events
  95. - (IBAction)btnAddDeviceTouched:(id)sender {
  96. }
  97. - (IBAction)btnCloseTouched:(id)sender {
  98. [self dismissViewControllerAnimated:YES completion:nil];
  99. }
  100. #pragma mark - MemoryWarning
  101. - (void)didReceiveMemoryWarning
  102. {
  103. [super didReceiveMemoryWarning];
  104. // Dispose of any resources that can be recreated.
  105. }
  106. @end