WeatherLocationPopupView.m 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. [self.imgTitleBar setImage:[UIImage imageNamed:@"img_popup_bg_head"]inset:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  40. [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  41. [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  42. [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  43. [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  44. //Localization
  45. [self.btnConfirm setTitle:NSLocalizedString(@"확인", @"확인") forState:UIControlStateNormal];
  46. [self.btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
  47. UIEdgeInsets insets = UIEdgeInsetsMake(1, 1, 1, 2);
  48. _bgCellImage1 = [ImageUtil resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch img:[UIImage imageNamed:@"img_list_bg_01"]];
  49. _bgCellImage2 = [ImageUtil resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch img:[UIImage imageNamed:@"img_list_bg_02"]];
  50. }
  51. }
  52. return self;
  53. }
  54. - (void)initTableViewAsDefaultStyle:(CustomTableView *)tableView {
  55. tableView.dataSource = self;
  56. tableView.delegate = self;
  57. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  58. tableView.backgroundColor = [UIColor clearColor];
  59. tableView.tableFooterView = [[UIView alloc] init]; //this call table events;
  60. }
  61. - (void)didMoveToSuperview {
  62. }
  63. - (CommonCode *)weatherLocation {
  64. return _rgroup.valueForChecked;
  65. }
  66. - (void)setLocations:(NSArray<CommonCode> *)locations {
  67. _locations = locations;
  68. _isNotFirstLoading = [_locations matchedObjectName:ksCustomRadioButtonStatus condition:YES] != nil;
  69. }
  70. #pragma mark - Main Logic
  71. #pragma mark - UITableView DataSource & Delegate
  72. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  73. return 1;
  74. }
  75. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  76. return _locations ? _locations.count : 0;
  77. }
  78. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  79. CGFloat height = 76.0f;
  80. return height;
  81. }
  82. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  83. CommonCode *code = _locations[indexPath.row];
  84. WeatherLocationPopupTableViewCell *tcell = (WeatherLocationPopupTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"LocationCellIdentifier"];
  85. tcell.lblCity.text = code.commonCodeName;
  86. tcell.rdoSelect.value = code;
  87. tcell.rdoSelect.checked = [tcell.rdoSelect getRadioStatusFromValue];
  88. // if (indexPath.row == 0 && !_isNotFirstLoading) {
  89. // _isNotFirstLoading = YES;
  90. // tcell.rdoSelect.checked = YES;
  91. // NSLog(@"1");
  92. // } else {
  93. // tcell.rdoSelect.checked = [tcell.rdoSelect getRadioStatusFromValue];
  94. // NSLog(@"2");
  95. // }
  96. [_rgroup addRadioButton:tcell.rdoSelect];
  97. //set background image
  98. // if (indexPath.row % 2 == 0) {
  99. // tcell.backgroundView = [[UIImageView alloc] initWithImage:_bgCellImage1];
  100. // } else {
  101. // tcell.backgroundView = [[UIImageView alloc] initWithImage:_bgCellImage2];
  102. // }
  103. //
  104. if (tcell.rdoSelect.checked) {
  105. tcell.backgroundView = [[UIImageView alloc] initWithImage:_bgCellImage1];
  106. } else {
  107. tcell.backgroundView = [[UIImageView alloc] initWithImage:_bgCellImage2];
  108. }
  109. return tcell;
  110. }
  111. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  112. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  113. WeatherLocationPopupTableViewCell *tcell = (WeatherLocationPopupTableViewCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
  114. [_rgroup someRadioButtonTouched:tcell.rdoSelect];
  115. [_tableView reloadData];
  116. }
  117. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  118. // Remove seperator inset
  119. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  120. [cell setSeparatorInset:UIEdgeInsetsZero];
  121. }
  122. // Prevent the cell from inheriting the Table View's margin settings
  123. if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
  124. [cell setPreservesSuperviewLayoutMargins:NO];
  125. }
  126. // Explictly set your cell's layout margins
  127. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  128. [cell setLayoutMargins:UIEdgeInsetsZero];
  129. }
  130. }
  131. #pragma mark - UI Events
  132. @end