WeatherLocationPopupView.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. //
  2. // WeatherLocationPopupView.m
  3. // kneet2
  4. //
  5. // Created by Jason Lee on 11/3/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "RequestHandler.h"
  10. #import "JDJSONModel.h"
  11. #import "CustomLabel.h"
  12. #import "CustomTableView.h"
  13. #import "CustomButton.h"
  14. #import "CustomRadioGroup.h"
  15. #import "ImageUtil.h"
  16. #import "WeatherLocationPopupView.h"
  17. @implementation WeatherLocationPopupTableViewCell
  18. @end
  19. @interface WeatherLocationPopupView () <UITableViewDataSource, UITableViewDelegate> {
  20. CustomRadioReusableGroup *_rgroup;
  21. BOOL _isNotFirstLoading;
  22. UIImage *_bgCellImage1, *_bgCellImage2;
  23. NSMutableArray<ItemModel> *_checkedDevices;
  24. }
  25. @end
  26. @implementation WeatherLocationPopupView
  27. - (id)initFromNib {
  28. for (UIView *view in [CommonUtil nibViews:@"WeatherLocationPopupView"]) {
  29. if ([view isKindOfClass:[WeatherLocationPopupView class]]) {
  30. self = (WeatherLocationPopupView *)view;
  31. //XIB의 경우, 현재 화면 사이즈로 맞춰줘야 함.
  32. self.frame = [UIScreen mainScreen].bounds;
  33. [self initTableViewAsDefaultStyle:_tableView];
  34. UINib *nib = [UINib nibWithNibName:@"WeatherLocationPopupTableViewCell" bundle:nil];
  35. [_tableView registerNib:nib forCellReuseIdentifier:@"LocationCellIdentifier"];
  36. //set radio group
  37. _rgroup = [[CustomRadioReusableGroup alloc] init];
  38. _rgroup.tableView = _tableView;
  39. //Localization
  40. [self.btnConfirm setTitle:NSLocalizedString(@"확인", @"확인") forState:UIControlStateNormal];
  41. [self.btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
  42. UIEdgeInsets insets = UIEdgeInsetsMake(1, 1, 1, 2);
  43. _bgCellImage1 = [ImageUtil resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch img:[UIImage imageNamed:@"img_list_bg_01"]];
  44. _bgCellImage2 = [ImageUtil resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch img:[UIImage imageNamed:@"img_list_bg_02"]];
  45. }
  46. }
  47. return self;
  48. }
  49. - (void)initTableViewAsDefaultStyle:(CustomTableView *)tableView {
  50. tableView.dataSource = self;
  51. tableView.delegate = self;
  52. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  53. tableView.backgroundColor = [UIColor clearColor];
  54. tableView.tableFooterView = [[UIView alloc] init]; //this call table events;
  55. }
  56. - (void)didMoveToSuperview {
  57. }
  58. - (CommonCode *)weatherLocation {
  59. return _rgroup.valueForChecked;
  60. }
  61. - (void)setLocations:(NSArray<CommonCode> *)locations {
  62. _locations = locations;
  63. _isNotFirstLoading = [_locations matchedObjectName:ksCustomRadioButtonStatus condition:YES] != nil;
  64. }
  65. #pragma mark - Main Logic
  66. #pragma mark - UITableView DataSource & Delegate
  67. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  68. return 1;
  69. }
  70. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  71. return _locations ? _locations.count : 0;
  72. }
  73. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  74. CGFloat height = 78.0f;
  75. return height;
  76. }
  77. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  78. CommonCode *code = _locations[indexPath.row];
  79. WeatherLocationPopupTableViewCell *tcell = (WeatherLocationPopupTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"LocationCellIdentifier"];
  80. tcell.lblCity.text = code.commonCodeName;
  81. tcell.rdoSelect.value = code;
  82. if (indexPath.row == 0 && !_isNotFirstLoading) {
  83. _isNotFirstLoading = YES;
  84. tcell.rdoSelect.checked = YES;
  85. } else {
  86. tcell.rdoSelect.checked = [tcell.rdoSelect getRadioStatusFromValue];
  87. }
  88. [_rgroup addRadioButton:tcell.rdoSelect];
  89. //set background image
  90. if (indexPath.row % 2 == 0) {
  91. tcell.backgroundView = [[UIImageView alloc] initWithImage:_bgCellImage1];
  92. } else {
  93. tcell.backgroundView = [[UIImageView alloc] initWithImage:_bgCellImage2];
  94. }
  95. return tcell;
  96. }
  97. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  98. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  99. WeatherLocationPopupTableViewCell *tcell = (WeatherLocationPopupTableViewCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
  100. [_rgroup someRadioButtonTouched:tcell.rdoSelect];
  101. [_tableView reloadData];
  102. }
  103. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  104. // Remove seperator inset
  105. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  106. [cell setSeparatorInset:UIEdgeInsetsZero];
  107. }
  108. // Prevent the cell from inheriting the Table View's margin settings
  109. if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
  110. [cell setPreservesSuperviewLayoutMargins:NO];
  111. }
  112. // Explictly set your cell's layout margins
  113. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  114. [cell setLayoutMargins:UIEdgeInsetsZero];
  115. }
  116. }
  117. #pragma mark - UI Events
  118. @end