// // RASettingViewController.m // Apex And Drivers // // Created by Jack on 2018/9/11. // Copyright © 2018年 USAI. All rights reserved. // #import "RASettingViewController.h" #import "RASettingSectionModel.h" @interface RASettingViewController () { NSMutableArray *_sections; } @property (nonatomic,strong) IBOutlet UITableView *settingTableView; @end @implementation RASettingViewController + (instancetype)viewControllerFromStoryboard { RASettingViewController *settingVC = [[UIStoryboard storyboardWithName:@"setting" bundle:nil] instantiateViewControllerWithIdentifier:[self storyboardID]]; return settingVC; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self configTableView]; [self loadData]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - Config - (void)configTableView { if (@available(iOS 11,*)) { self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } // else { // self.automaticallyAdjustsScrollViewInsets = NO; // } // self.tableView.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1]; } #pragma mark - Getter - (UITableView *)tableView { return self.settingTableView; } - (NSArray *)sections { if (!_sections) { _sections = [NSMutableArray array]; } return _sections; } #pragma mark - Data - (void)loadData { dispatch_async(dispatch_get_global_queue(0, 0), ^{ NSDictionary *json = [RADataProvider loadDataFromBundleFile:@"setting.json"]; NSMutableArray *tmpArr = [NSMutableArray array]; NSArray *sectionArr = [json objectForKey:@"sections"]; for (NSDictionary *section in sectionArr) { RASettingSectionModel *model = [RASettingSectionModel new]; [model setValuesForKeysWithDictionary:section]; [tmpArr addObject:model]; } NSMutableArray *sections = (NSMutableArray *)self.sections; [sections removeAllObjects]; [sections addObjectsFromArray:tmpArr]; dispatch_async(dispatch_get_main_queue(), ^{ [self.tableView reloadData]; }); }); } @end