RASettingViewController.m 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. } else {
  36. self.automaticallyAdjustsScrollViewInsets = NO;
  37. }
  38. self.tableView.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1];
  39. }
  40. #pragma mark - Getter
  41. - (UITableView *)tableView {
  42. return self.settingTableView;
  43. }
  44. - (NSArray<RASettingSectionModel *> *)sections {
  45. if (!_sections) {
  46. _sections = [NSMutableArray array];
  47. }
  48. return _sections;
  49. }
  50. #pragma mark - Data
  51. - (void)loadData {
  52. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  53. NSDictionary *json = [RADataProvider loadDataFromBundleFile:@"setting.json"];
  54. NSMutableArray *tmpArr = [NSMutableArray array];
  55. NSArray *sectionArr = [json objectForKey:@"sections"];
  56. for (NSDictionary *section in sectionArr) {
  57. RASettingSectionModel *model = [RASettingSectionModel new];
  58. [model setValuesForKeysWithDictionary:section];
  59. [tmpArr addObject:model];
  60. }
  61. NSMutableArray *sections = (NSMutableArray *)self.sections;
  62. [sections removeAllObjects];
  63. [sections addObjectsFromArray:tmpArr];
  64. dispatch_async(dispatch_get_main_queue(), ^{
  65. [self.tableView reloadData];
  66. });
  67. });
  68. }
  69. @end