| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- //
- // 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 () <UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic,strong) IBOutlet UITableView *optionTable;
- @property (nonatomic,strong) NSArray<RASettingOption *> *options;
- @property (nonatomic,assign) NSInteger selectedIndex;
- @end
- @implementation RAOptionViewController
- + (instancetype)optionViewControllerWith:(NSArray<RASettingOption *> *)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 {
-
- 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
|