RASettingViewController.m 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // RASettingViewController.m
  3. // Apex And Drivers
  4. //
  5. // Created by Jack on 2018/9/11.
  6. // Copyright © 2018年 USAI. All rights reserved.
  7. //
  8. #import "RASettingViewController.h"
  9. #import "RASettingSectionModel.h"
  10. @interface RASettingViewController ()
  11. {
  12. NSMutableArray<RASettingSectionModel *> *_sections;
  13. }
  14. @property (nonatomic,strong) IBOutlet UITableView *settingTableView;
  15. @end
  16. @implementation RASettingViewController
  17. + (instancetype)viewControllerFromStoryboard {
  18. RASettingViewController *settingVC = [[UIStoryboard storyboardWithName:@"setting" bundle:nil] instantiateViewControllerWithIdentifier:[self storyboardID]];
  19. return settingVC;
  20. }
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. // Do any additional setup after loading the view.
  24. [self configTableView];
  25. [self loadData];
  26. }
  27. - (void)didReceiveMemoryWarning {
  28. [super didReceiveMemoryWarning];
  29. // Dispose of any resources that can be recreated.
  30. }
  31. #pragma mark - Config
  32. - (void)configTableView {
  33. if (@available(iOS 11,*)) {
  34. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  35. }
  36. // else {
  37. // self.automaticallyAdjustsScrollViewInsets = NO;
  38. // }
  39. //
  40. self.tableView.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1];
  41. }
  42. #pragma mark - Getter
  43. - (UITableView *)tableView {
  44. return self.settingTableView;
  45. }
  46. - (NSArray<RASettingSectionModel *> *)sections {
  47. if (!_sections) {
  48. _sections = [NSMutableArray array];
  49. }
  50. return _sections;
  51. }
  52. #pragma mark - Data
  53. - (void)loadData {
  54. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  55. NSDictionary *json = [RADataProvider loadDataFromBundleFile:@"setting.json"];
  56. NSMutableArray *tmpArr = [NSMutableArray array];
  57. NSArray *sectionArr = [json objectForKey:@"sections"];
  58. for (NSDictionary *section in sectionArr) {
  59. RASettingSectionModel *model = [RASettingSectionModel new];
  60. [model setValuesForKeysWithDictionary:section];
  61. [tmpArr addObject:model];
  62. }
  63. NSMutableArray *sections = (NSMutableArray *)self.sections;
  64. [sections removeAllObjects];
  65. [sections addObjectsFromArray:tmpArr];
  66. dispatch_async(dispatch_get_main_queue(), ^{
  67. [self.tableView reloadData];
  68. });
  69. });
  70. }
  71. @end