RAOptionViewController.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //
  2. // RAOptionViewController.m
  3. // Apex And Drivers
  4. //
  5. // Created by Jack on 2018/9/12.
  6. // Copyright © 2018年 USAI. All rights reserved.
  7. //
  8. #import "RAOptionViewController.h"
  9. #import "RASettingOptionModel.h"
  10. #import "RAOptionCell.h"
  11. @interface RAOptionViewController () <UITableViewDelegate,UITableViewDataSource>
  12. @property (nonatomic,strong) IBOutlet UITableView *optionTable;
  13. @property (nonatomic,strong) NSArray<RASettingOption *> *options;
  14. @property (nonatomic,assign) NSInteger selectedIndex;
  15. @end
  16. @implementation RAOptionViewController
  17. + (instancetype)optionViewControllerWith:(NSArray<RASettingOption *> *)options selectedIndex:(NSInteger)index {
  18. RAOptionViewController *optionVC = [self viewControllerFromStoryboard];
  19. optionVC.options = options;
  20. optionVC.selectedIndex = index;
  21. return optionVC;
  22. }
  23. + (instancetype)viewControllerFromStoryboard {
  24. RAOptionViewController *optionVC = [[UIStoryboard storyboardWithName:@"setting" bundle:nil] instantiateViewControllerWithIdentifier:[self storyboardID]];
  25. return optionVC;
  26. }
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. // Do any additional setup after loading the view.
  30. [self configTable];
  31. }
  32. - (void)didReceiveMemoryWarning {
  33. [super didReceiveMemoryWarning];
  34. // Dispose of any resources that can be recreated.
  35. }
  36. #pragma mark - config
  37. - (void)configTable {
  38. if (@available(iOS 11,*)) {
  39. self.optionTable.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  40. }
  41. // else {
  42. // self.automaticallyAdjustsScrollViewInsets = NO;
  43. // }
  44. self.optionTable.tableFooterView = [UIView new];
  45. self.optionTable.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1];
  46. }
  47. #pragma mark - Table
  48. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  49. return 1;
  50. }
  51. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  52. return self.options.count;
  53. }
  54. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  55. RAOptionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RAOptionCell" forIndexPath:indexPath];
  56. RASettingOption *option = [self.options objectAtIndex:indexPath.row];
  57. [cell setTitle:option.title];
  58. if (self.selectedIndex == indexPath.row) {
  59. cell.accessoryType = UITableViewCellAccessoryCheckmark;
  60. } else {
  61. cell.accessoryType = UITableViewCellAccessoryNone;
  62. }
  63. return cell;
  64. }
  65. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  66. return 50.0f;
  67. }
  68. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  69. return 25.0f;
  70. }
  71. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  72. UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(tableView.bounds), 25.0f)];
  73. // header.backgroundColor = ApexDriverGrayColor;
  74. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5, 2, CGRectGetWidth(tableView.bounds) - 20, 21)];
  75. label.font = [UIFont systemFontOfSize:14.0f];
  76. label.textColor = [UIColor grayColor];
  77. // label.textColor = ApexDriverWhiteColor;
  78. [header addSubview:label];
  79. label.text = self.optionTitle;
  80. return header;
  81. }
  82. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  83. self.selectedIndex = indexPath.row;
  84. if (self.selectBlk) {
  85. self.selectBlk(self.selectedIndex);
  86. }
  87. [tableView reloadData];
  88. }
  89. @end