// // AgreementViewController.m // kneet2 // // Created by Jason Lee on 10/15/15. // Copyright © 2015 ntels. All rights reserved. // #import "AgreementViewController.h" #import "CustomLabel.h" #import "CustomCheckBox.h" #import "CustomTableView.h" #import "WebBrowseViewController.h" @implementation AgreementTermTableViewCell - (void)didMoveToSuperview { [_lblTitle setUnderLine:_lblTitle.text]; } @end @implementation AgreementServiceTableViewCell - (void)didMoveToSuperview { [_lblTitle setUnderLine:_lblTitle.text]; } @end @implementation AgreementAllTableViewCell - (void)didMoveToSuperview { } @end @implementation AgreementGuideTableViewCell - (void)didMoveToSuperview { [_lblGuide setUnderLine:_lblGuide.text]; } @end @interface AgreementViewController () { NSArray *_tableZombieValues; CustomCheckBox *_chkTerm, *_chkService, *_chkAll; } @end #pragma mark - Class Definition @implementation AgreementViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self initUI]; [self prepareViewDidLoad]; } - (void)initUI { _tableZombieValues = @[@"t0", @"t1", @"t2", @"t3"]; [self initTableViewAsDefaultStyle:_tableView]; } - (void)prepareViewDidLoad { } #pragma mark - Main Logic #pragma mark - UITableView DataSource & Delegate - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 4; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { CGFloat height = 65; if (indexPath.row == 2) { height = 80; } else if (indexPath.row == 3) { height = 115; } return height; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = nil; NSString *tzombie = _tableZombieValues[indexPath.row]; if (indexPath.row == 0) { AgreementTermTableViewCell *tcell = (AgreementTermTableViewCell * )[tableView dequeueReusableCellWithIdentifier:@"TermCellIdentifier"]; if (!_chkTerm) { _chkTerm = tcell.chkAgree; } tcell.chkAgree.delegate = self; tcell.chkAgree.value = tzombie; tcell.chkAgree.checked = [tcell.chkAgree getCheckStatusFromValue]; cell = tcell; } else if (indexPath.row == 1) { AgreementServiceTableViewCell *tcell = (AgreementServiceTableViewCell * )[tableView dequeueReusableCellWithIdentifier:@"ServiceCellIdentifier"]; if (!_chkService) { _chkService = tcell.chkAgree; } tcell.chkAgree.delegate = self; tcell.chkAgree.value = tzombie; tcell.chkAgree.checked = [tcell.chkAgree getCheckStatusFromValue]; cell = tcell; } else if (indexPath.row == 2) { AgreementAllTableViewCell *tcell = (AgreementAllTableViewCell * )[tableView dequeueReusableCellWithIdentifier:@"AllCellIdentifier"]; if (!_chkAll) { _chkAll = tcell.chkAgree; } tcell.chkAgree.delegate = self; tcell.chkAgree.value = tzombie; tcell.chkAgree.checked = [tcell.chkAgree getCheckStatusFromValue]; cell = tcell; } else if (indexPath.row == 3) {//Guide AgreementGuideTableViewCell *tcell = (AgreementGuideTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"GuideCellIdentifier"]; cell = tcell; } return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [super tableView:tableView didSelectRowAtIndexPath:indexPath]; if (indexPath.row == 2 || indexPath.row == 3) { return; } WebBrowseViewController *vc = (WebBrowseViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"WebBrowseViewController" storyboardName:@"Common"]; if (indexPath.row == 0) { vc.titleString = NSLocalizedString(@"서비스 이용약관", @"서비스 이용약관"); vc.URLString = [NSString stringWithFormat:@"%@/guide/service", kAPIServer]; } else if (indexPath.row == 1) { vc.titleString = NSLocalizedString(@"개인정보 취급정책", @"개인정보 취급정책"); vc.URLString = [NSString stringWithFormat:@"%@/guide/policy", kAPIServer]; } vc.providesPresentationContextTransitionStyle = YES; vc.definesPresentationContext = YES; [vc setModalPresentationStyle:UIModalPresentationOverCurrentContext]; [self presentViewController:vc animated:YES completion:nil]; } #pragma mark - CustomCheckBox Delegate { - (void)didCheckBoxClicked:(id)sender { if ([sender isEqual:_chkAll]) { _chkTerm.checked = _chkService.checked = _chkAll.checked; } else { if (_chkTerm.checked && _chkService.checked) { _chkAll.checked = YES; } else { _chkAll.checked = NO; } } } #pragma mark - UI Events - (IBAction)btnNextTouched:(id)sender { if (!_chkAll.checked) { [[JDFacade facade] toast:@"모든 약관에 동의해주세요"]; return; } UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"SignUpViewController" storyboardName:@"SignUp"]; vc.providesPresentationContextTransitionStyle = YES; vc.definesPresentationContext = YES; [vc setModalPresentationStyle:UIModalPresentationOverCurrentContext]; [self presentViewController:vc animated:YES completion:nil]; } - (IBAction)btnCancelTouched:(id)sender { [self dismissViewControllerAnimated:YES completion:nil]; } #pragma mark - MemoryWarning - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end