ThingsInfoViewController.m 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. //
  2. // ThingsInfoViewController.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 4/21/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "DeviceModel.h"
  10. #import "CustomLabel.h"
  11. #import "CustomButton.h"
  12. #import "ThingsInfoViewController.h"
  13. #define kfThingsInfoTableViewCellHeight 64.0f
  14. @implementation ThingsInfoTableViewCell
  15. - (void)awakeFromNib {
  16. self.selectionStyle = UITableViewCellSelectionStyleNone;
  17. }
  18. @end
  19. @interface ThingsInfoViewController () <UITableViewDelegate, UITableViewDataSource> {
  20. NSMutableArray *_dataArray;
  21. }
  22. @end
  23. #pragma mark - Class Definition
  24. @implementation ThingsInfoViewController
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. // Do any additional setup after loading the view.
  28. [self initUI];
  29. [self prepareViewDidLoad];
  30. }
  31. - (void)initUI {
  32. //set tableview option
  33. _tableView.dataSource = self;
  34. _tableView.delegate = self;
  35. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  36. _tableView.backgroundColor = [UIColor clearColor];
  37. _tableView.tableFooterView = [[UIView alloc] init]; //this call table events;
  38. //Localization
  39. [_btnClose setTitle:NSLocalizedString(@"닫기", @"닫기") forState:UIControlStateNormal];
  40. }
  41. - (void)prepareViewDidLoad {
  42. _dataArray = [[NSMutableArray alloc] init];
  43. if (_deviceDetail.prdName && ![_deviceDetail.prdName isEmptyString]) {
  44. [_dataArray addObject:@{@"title": NSLocalizedString(@"제품명", @"제품명"), @"content": _deviceDetail.prdName}];
  45. }
  46. if (_deviceDetail.deviceModelId && ![_deviceDetail.deviceModelId isEmptyString]) {
  47. [_dataArray addObject:@{@"title": NSLocalizedString(@"모델넘버", @"모델넘버"), @"content": _deviceDetail.deviceModelId}];
  48. }
  49. if (_deviceDetail.deviceMfId && ![_deviceDetail.deviceMfId isEmptyString]) {
  50. [_dataArray addObject:@{@"title": NSLocalizedString(@"제조사", @"제조사"), @"content": _deviceDetail.deviceMfId}];
  51. }
  52. if (_deviceDetail.firmwareVersion && ![_deviceDetail.firmwareVersion isEmptyString]) {
  53. [_dataArray addObject:@{@"title": NSLocalizedString(@"펌웨어", @"펌웨어"), @"content": _deviceDetail.firmwareVersion}];
  54. }
  55. if (_deviceDetail.createDatetime && ![_deviceDetail.createDatetime isEmptyString]) {
  56. [_dataArray addObject:@{@"title": NSLocalizedString(@"등록일시", @"등록일시"), @"content": _deviceDetail.createDatetime}];
  57. }
  58. if (_deviceDetail.deviceProtocolType && ![_deviceDetail.deviceProtocolType isEmptyString]) {
  59. [_dataArray addObject:@{@"title": NSLocalizedString(@"연결타입", @"연결타입"), @"content": _deviceDetail.deviceProtocolType}];
  60. }
  61. if (_deviceDetail.relateDevice && _deviceDetail.relateDevice.count) {
  62. NSString *title = nil;
  63. if ([_deviceDetail.deviceType isEqualToString:ksDeviceTypeSlave]) {
  64. title = NSLocalizedString(@"상위 장치", @"상위 장치");
  65. } else if ([_deviceDetail.deviceType isEqualToString:ksDeviceTypeControllerPrimary]) {
  66. title = NSLocalizedString(@"하위 장치", @"하위 장치");
  67. }
  68. NSMutableString *rdeviceString = [[NSMutableString alloc] init];
  69. for (DeviceModel *rdevice in _deviceDetail.relateDevice) {
  70. NSString *prefix = [rdeviceString isEmptyString] ? ksEmptyString : @", ";
  71. [rdeviceString appendFormat:@"%@%@", prefix, rdevice.deviceName];
  72. }
  73. [_dataArray addObject:@{@"title": title, @"content": rdeviceString}];
  74. }
  75. }
  76. #pragma mark - Main Logic
  77. #pragma mark - UITableView DataSource & Delegate
  78. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  79. return 1;
  80. }
  81. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  82. return _dataArray.count;
  83. }
  84. - (CGFloat)calculateContent:(NSString *)content {
  85. if ([content isEmptyString]) {
  86. return 0.0f;
  87. }
  88. CGFloat width = IPHONE_WIDTH - 90;
  89. UIFont *lfont = [UIFont boldSystemFontOfSize:kUIFontSize04];
  90. CGFloat nheight = [CommonUtil getSizeFromString:content font:lfont width:width].height;
  91. nheight = nheight < 22 ? 22.0f : fabs(nheight) + 7.0f; //adjust padding
  92. return nheight;
  93. }
  94. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  95. CGFloat height = kfThingsInfoTableViewCellHeight;
  96. NSDictionary *dic = _dataArray[indexPath.row];
  97. CGFloat contentHeight = [self calculateContent:dic[@"content"]];
  98. height = 42.0f + contentHeight; //(title.height + padding)
  99. return height;
  100. }
  101. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  102. static NSString *CellIdentifier = @"CellIdentifier";
  103. ThingsInfoTableViewCell *cell = (ThingsInfoTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  104. if (cell == nil) {
  105. cell = [[ThingsInfoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  106. }
  107. NSDictionary *dic = _dataArray[indexPath.row];
  108. cell.lblTitle.text = dic[@"title"];
  109. cell.lblContent.text = dic[@"content"];
  110. return cell;
  111. }
  112. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  113. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  114. }
  115. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  116. // Remove seperator inset
  117. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  118. [cell setSeparatorInset:UIEdgeInsetsZero];
  119. }
  120. // Prevent the cell from inheriting the Table View's margin settings
  121. if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
  122. [cell setPreservesSuperviewLayoutMargins:NO];
  123. }
  124. // Explictly set your cell's layout margins
  125. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  126. [cell setLayoutMargins:UIEdgeInsetsZero];
  127. }
  128. }
  129. #pragma mark - UI Events
  130. #pragma mark - MemoryWarning
  131. - (void)didReceiveMemoryWarning
  132. {
  133. [super didReceiveMemoryWarning];
  134. // Dispose of any resources that can be recreated.
  135. }
  136. @end