ThingsAddViewController.m 4.2 KB

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