| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- //
- // WeatherLocationPopupView.m
- // kneet2
- //
- // Created by Jason Lee on 11/3/15.
- // Copyright (c) 2015 ntels. All rights reserved.
- //
- #import "JDObject.h"
- #import "RequestHandler.h"
- #import "JDJSONModel.h"
- #import "CustomLabel.h"
- #import "CustomTableView.h"
- #import "CustomButton.h"
- #import "CustomRadioGroup.h"
- #import "ImageUtil.h"
- #import "WeatherLocationPopupView.h"
- @implementation WeatherLocationPopupTableViewCell
- @end
- @interface WeatherLocationPopupView () <UITableViewDataSource, UITableViewDelegate> {
-
- CustomRadioReusableGroup *_rgroup;
- BOOL _isNotFirstLoading;
- UIImage *_bgCellImage1, *_bgCellImage2;
-
- NSMutableArray<ItemModel> *_checkedDevices;
- }
- @end
- @implementation WeatherLocationPopupView
- - (id)initFromNib {
- for (UIView *view in [CommonUtil nibViews:@"WeatherLocationPopupView"]) {
- if ([view isKindOfClass:[WeatherLocationPopupView class]]) {
- self = (WeatherLocationPopupView *)view;
- //XIB의 경우, 현재 화면 사이즈로 맞춰줘야 함.
- self.frame = [UIScreen mainScreen].bounds;
-
- [self initTableViewAsDefaultStyle:_tableView];
-
- UINib *nib = [UINib nibWithNibName:@"WeatherLocationPopupTableViewCell" bundle:nil];
- [_tableView registerNib:nib forCellReuseIdentifier:@"LocationCellIdentifier"];
-
- //set radio group
- _rgroup = [[CustomRadioReusableGroup alloc] init];
- _rgroup.tableView = _tableView;
-
- [self.imgTitleBar setImage:[UIImage imageNamed:@"img_popup_bg_head"]inset:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
-
-
- [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
- [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
-
-
- [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
- [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
-
- //Localization
- [self.btnConfirm setTitle:NSLocalizedString(@"확인", @"확인") forState:UIControlStateNormal];
- [self.btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
-
- UIEdgeInsets insets = UIEdgeInsetsMake(1, 1, 1, 2);
- _bgCellImage1 = [ImageUtil resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch img:[UIImage imageNamed:@"img_list_bg_01"]];
- _bgCellImage2 = [ImageUtil resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch img:[UIImage imageNamed:@"img_list_bg_02"]];
- }
- }
- return self;
- }
- - (void)initTableViewAsDefaultStyle:(CustomTableView *)tableView {
- tableView.dataSource = self;
- tableView.delegate = self;
-
- tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- tableView.backgroundColor = [UIColor clearColor];
-
- tableView.tableFooterView = [[UIView alloc] init]; //this call table events;
- }
- - (void)didMoveToSuperview {
- }
- - (CommonCode *)weatherLocation {
- return _rgroup.valueForChecked;
- }
- - (void)setLocations:(NSArray<CommonCode> *)locations {
- _locations = locations;
-
- _isNotFirstLoading = [_locations matchedObjectName:ksCustomRadioButtonStatus condition:YES] != nil;
- }
- #pragma mark - Main Logic
- #pragma mark - UITableView DataSource & Delegate
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return _locations ? _locations.count : 0;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- CGFloat height = 76.0f;
-
- return height;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- CommonCode *code = _locations[indexPath.row];
-
- WeatherLocationPopupTableViewCell *tcell = (WeatherLocationPopupTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"LocationCellIdentifier"];
- tcell.lblCity.text = code.commonCodeName;
- tcell.rdoSelect.value = code;
-
- tcell.rdoSelect.checked = [tcell.rdoSelect getRadioStatusFromValue];
- // if (indexPath.row == 0 && !_isNotFirstLoading) {
- // _isNotFirstLoading = YES;
- // tcell.rdoSelect.checked = YES;
- // NSLog(@"1");
- // } else {
- // tcell.rdoSelect.checked = [tcell.rdoSelect getRadioStatusFromValue];
- // NSLog(@"2");
- // }
-
- [_rgroup addRadioButton:tcell.rdoSelect];
-
- //set background image
- // if (indexPath.row % 2 == 0) {
- // tcell.backgroundView = [[UIImageView alloc] initWithImage:_bgCellImage1];
- // } else {
- // tcell.backgroundView = [[UIImageView alloc] initWithImage:_bgCellImage2];
- // }
- //
- if (tcell.rdoSelect.checked) {
- tcell.backgroundView = [[UIImageView alloc] initWithImage:_bgCellImage1];
- } else {
- tcell.backgroundView = [[UIImageView alloc] initWithImage:_bgCellImage2];
- }
- return tcell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
-
- WeatherLocationPopupTableViewCell *tcell = (WeatherLocationPopupTableViewCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
- [_rgroup someRadioButtonTouched:tcell.rdoSelect];
-
- [_tableView reloadData];
- }
- - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
-
- // Remove seperator inset
- if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
- [cell setSeparatorInset:UIEdgeInsetsZero];
- }
-
- // Prevent the cell from inheriting the Table View's margin settings
- if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
- [cell setPreservesSuperviewLayoutMargins:NO];
- }
-
- // Explictly set your cell's layout margins
- if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
- [cell setLayoutMargins:UIEdgeInsetsZero];
- }
- }
- #pragma mark - UI Events
- @end
|