PopTableView.m 5.5 KB

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