RAOptionViewController.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. self.optionTable.tableFooterView = [UIView new];
  39. self.optionTable.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1];
  40. }
  41. #pragma mark - Table
  42. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  43. return 1;
  44. }
  45. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  46. return self.options.count;
  47. }
  48. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  49. RAOptionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RAOptionCell" forIndexPath:indexPath];
  50. RASettingOption *option = [self.options objectAtIndex:indexPath.row];
  51. [cell setTitle:option.title];
  52. if (self.selectedIndex == indexPath.row) {
  53. cell.accessoryType = UITableViewCellAccessoryCheckmark;
  54. } else {
  55. cell.accessoryType = UITableViewCellAccessoryNone;
  56. }
  57. return cell;
  58. }
  59. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  60. return 50.0f;
  61. }
  62. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  63. return 25.0f;
  64. }
  65. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  66. UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(tableView.bounds), 25.0f)];
  67. // header.backgroundColor = ApexDriverGrayColor;
  68. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5, 2, CGRectGetWidth(tableView.bounds) - 20, 21)];
  69. label.font = [UIFont systemFontOfSize:14.0f];
  70. label.textColor = [UIColor grayColor];
  71. // label.textColor = ApexDriverWhiteColor;
  72. [header addSubview:label];
  73. label.text = self.optionTitle;
  74. return header;
  75. }
  76. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  77. self.selectedIndex = indexPath.row;
  78. if (self.selectBlk) {
  79. self.selectBlk(self.selectedIndex);
  80. }
  81. [tableView reloadData];
  82. }
  83. @end