// // RASettingViewController+TableDataSource.m // Apex And Drivers // // Created by Jack on 2018/9/12. // Copyright © 2018年 USAI. All rights reserved. // #import "RASettingViewController+TableDataSource.h" #import "RASettingSectionModel.h" #import "RASettingOptionModel.h" #import "RASettingSwitchModel.h" #import "RASettingActionModel.h" #import "RASettingOptionCell.h" #import "RASettingSwitchCell.h" #import "RASettingActionCell.h" #import "RASettingAboutCell.h" @implementation RASettingViewController (TableDataSource) - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return self.sections.count; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { RASettingSectionModel *sectionModel = [self.sections objectAtIndex:section]; return sectionModel.settings.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { RASettingSectionModel *sectionModel = [self.sections objectAtIndex:indexPath.section]; RASettingBaseModel *model = [sectionModel.settings objectAtIndex:indexPath.row]; RASettingBaseCell *cell = nil; switch (model.type) { case RASettingTypeOption: { cell = [tableView dequeueReusableCellWithIdentifier:@"RASettingOptionCell" forIndexPath:indexPath]; } break; case RASettingTypeSwitch: { cell = [tableView dequeueReusableCellWithIdentifier:@"RASettingSwitchCell" forIndexPath:indexPath]; } break; case RASettingTypeAction: { cell = [tableView dequeueReusableCellWithIdentifier:@"RASettingActionCell" forIndexPath:indexPath]; } break; case RASettingTypeAbout: { cell = [tableView dequeueReusableCellWithIdentifier:@"RASettingAboutCell" forIndexPath:indexPath]; } break; case RASettingTypeLink: { cell = [tableView dequeueReusableCellWithIdentifier:@"RASettingLinkCell" forIndexPath:indexPath]; } break; default: { cell = [RASettingBaseCell new]; } break; } [cell setModel:model]; return cell; } @end