PopTableView.m 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. //
  2. // PopTableView.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 4/27/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "CustomLabel.h"
  10. #import "CustomRadioGroup.h"
  11. #import "PopTableView.h"
  12. #import "CustomImageView.h"
  13. #import "ImageUtil.h"
  14. #define kfPopTableViewCellHeight 100.0f
  15. @interface PopRadioTableViewCell : UITableViewCell
  16. @property (strong, nonatomic) CustomLabel *lblTitle;
  17. @property (strong, nonatomic) CustomRadioButton *rdoSelect;
  18. @end
  19. @implementation PopRadioTableViewCell
  20. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  21. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  22. CGFloat width = IPHONE_WIDTH - 20 - 20 - 25 - 10; //margin - margin - radiosize - padding
  23. self.lblTitle = [[CustomLabel alloc] initWithFrame:CGRectMake(20, 20, width, 60)];
  24. _lblTitle.numberOfLines = 0;
  25. _lblTitle.font = [UIFont systemFontOfSize:kUIFontSize02];
  26. _lblTitle.textColor = kUITextColor01;
  27. self.rdoSelect = [[CustomRadioButton alloc] initWithFrame:CGRectMake(width+10, 37.5, 25.0f, 25.0f) normalImage:[UIImage imageNamed:@"common_radiobox_default"] highlightImage:[UIImage imageNamed:@"common_radiobox_checked"]];
  28. [self addSubview:_lblTitle];
  29. [self addSubview:_rdoSelect];
  30. self.backgroundColor = [UIColor clearColor];
  31. self.selectionStyle = UITableViewCellSelectionStyleNone;
  32. }
  33. return self;
  34. }
  35. @end
  36. @interface PopTableView () <UITableViewDataSource, UITableViewDelegate> {
  37. UIImage *_bgCellImage;
  38. BOOL _isNotFirstLoading;
  39. }
  40. @end
  41. @implementation PopTableView
  42. - (id)initFromNib {
  43. for (UIView *view in [CommonUtil nibViews:@"PopTableView"]) {
  44. if ([view isKindOfClass:[PopTableView class]]) {
  45. self = (PopTableView *)view;
  46. //XIB의 경우, 현재 화면 사이즈로 맞춰줘야 함.
  47. self.frame = [UIScreen mainScreen].bounds;
  48. self.lblTitle.text = NSLocalizedString(@"주소검색",nil);
  49. _tableView.dataSource = self;
  50. _tableView.delegate = self;
  51. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  52. _tableView.backgroundColor = [UIColor clearColor];
  53. _tableView.scrollEnabled = YES;
  54. _tableView.tableFooterView = [[UIView alloc] init];
  55. _rgroup = [[CustomRadioReusableGroup alloc] init];
  56. _rgroup.tableView = _tableView;
  57. UIEdgeInsets insets = UIEdgeInsetsMake(4, 4, 4, 4);
  58. _bgCellImage = [ImageUtil resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch img:[UIImage imageNamed:@"tp_01_img_list_bg_02"]];
  59. [self.imgTitleBar setImage:[UIImage imageNamed:@"img_popup_bg_head"]inset:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  60. [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  61. [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  62. [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  63. [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  64. //Localization
  65. [self.btnConfirm setTitle:NSLocalizedString(@"선택", @"선택") forState:UIControlStateNormal];
  66. [self.btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
  67. }
  68. }
  69. return self;
  70. }
  71. - (void)didMoveToSuperview {
  72. }
  73. - (void)setDataArray:(NSArray *)dataArray {
  74. _dataArray = dataArray;
  75. // _tableViewHeightConstraint.constant = kfPopTableViewCellHeight * _dataArray.count;
  76. [_tableView reloadData];
  77. }
  78. #pragma mark - UITableView DataSource & Delegate
  79. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  80. return 1;
  81. }
  82. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  83. return _dataArray.count;
  84. }
  85. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  86. static NSString *CellIdentifier = @"CellIdentifier";
  87. PopRadioTableViewCell *cell = (PopRadioTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  88. if (cell == nil) {
  89. cell = [[PopRadioTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  90. }
  91. NSDictionary *component = _dataArray[indexPath.row];
  92. NSString *addr = component[@"formatted_address"];
  93. addr = [addr stringByReplacingOccurrencesOfString:@"대한민국 " withString:ksEmptyString];
  94. cell.lblTitle.text = addr;
  95. cell.rdoSelect.value = component;
  96. if (indexPath.row == 0 && !_isNotFirstLoading) {
  97. _isNotFirstLoading = YES;
  98. cell.rdoSelect.checked = YES;
  99. } else {
  100. cell.rdoSelect.checked = [cell.rdoSelect getRadioStatusFromValue];
  101. }
  102. [_rgroup addRadioButton:cell.rdoSelect];
  103. cell.backgroundView = [[UIImageView alloc] initWithImage:_bgCellImage];
  104. return cell;
  105. }
  106. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  107. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  108. PopRadioTableViewCell *cell = (PopRadioTableViewCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
  109. [_rgroup someRadioButtonTouched:cell.rdoSelect];
  110. [_tableView reloadData];
  111. }
  112. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  113. // Remove seperator inset
  114. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  115. [cell setSeparatorInset:UIEdgeInsetsZero];
  116. }
  117. // Prevent the cell from inheriting the Table View's margin settings
  118. if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
  119. [cell setPreservesSuperviewLayoutMargins:NO];
  120. }
  121. // Explictly set your cell's layout margins
  122. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  123. [cell setLayoutMargins:UIEdgeInsetsZero];
  124. }
  125. }
  126. @end