// // RAOptionViewController.m // Apex And Drivers // // Created by Jack on 2018/9/12. // Copyright © 2018年 USAI. All rights reserved. // #import "RAOptionViewController.h" #import "RASettingOptionModel.h" #import "RAOptionCell.h" @interface RAOptionViewController () @property (nonatomic,strong) IBOutlet UITableView *optionTable; @property (nonatomic,strong) NSArray *options; @property (nonatomic,assign) NSInteger selectedIndex; @end @implementation RAOptionViewController + (instancetype)optionViewControllerWith:(NSArray *)options selectedIndex:(NSInteger)index { RAOptionViewController *optionVC = [self viewControllerFromStoryboard]; optionVC.options = options; optionVC.selectedIndex = index; return optionVC; } + (instancetype)viewControllerFromStoryboard { RAOptionViewController *optionVC = [[UIStoryboard storyboardWithName:@"setting" bundle:nil] instantiateViewControllerWithIdentifier:[self storyboardID]]; return optionVC; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self configTable]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - config - (void)configTable { if (@available(iOS 11,*)) { self.optionTable.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } else { self.automaticallyAdjustsScrollViewInsets = NO; } self.optionTable.tableFooterView = [UIView new]; self.optionTable.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1]; } #pragma mark - Table - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.options.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { RAOptionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RAOptionCell" forIndexPath:indexPath]; RASettingOption *option = [self.options objectAtIndex:indexPath.row]; [cell setTitle:option.title]; if (self.selectedIndex == indexPath.row) { cell.accessoryType = UITableViewCellAccessoryCheckmark; } else { cell.accessoryType = UITableViewCellAccessoryNone; } return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 50.0f; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 25.0f; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(tableView.bounds), 25.0f)]; // header.backgroundColor = ApexDriverGrayColor; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5, 2, CGRectGetWidth(tableView.bounds) - 20, 21)]; label.font = [UIFont systemFontOfSize:14.0f]; label.textColor = [UIColor grayColor]; // label.textColor = ApexDriverWhiteColor; [header addSubview:label]; label.text = self.optionTitle; return header; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { self.selectedIndex = indexPath.row; if (self.selectBlk) { self.selectBlk(self.selectedIndex); } [tableView reloadData]; } @end