Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ALGenericTableViewDataSource.m
- // AddisonLeeiOS
- //
- // Created by Leonid Grebeniuk on 7/14/16.
- // Copyright © 2016 DMI. All rights reserved.
- //
- #import "ALGenericTableViewDataSource.h"
- @implementation ALGenericTableViewDataSource
- - (instancetype)initWithData:(NSArray *)dataArray
- {
- self = [super init];
- if (self) {
- self.dataArray = dataArray;
- }
- return self;
- }
- #pragma mark - UITableViewDataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return [self.dataArray count];
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return [self.dataArray[section] count];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- NSDictionary *dataCell = [self dataAtIndexPath:indexPath];
- UITableViewCell <ALCellProtocol> *cell = [tableView dequeueReusableCellWithIdentifier:dataCell[kKeyClassCellName]
- forIndexPath:indexPath];
- if (self.delegate != nil && [cell respondsToSelector:@selector(setDelegate:)]) {
- cell.delegate = self.delegate;
- }
- [cell populateCellWithData:dataCell];
- return cell;
- }
- #pragma mark - Helper
- - (NSDictionary *)dataAtIndexPath:(NSIndexPath *)indexPath {
- NSArray *sectionArray = self.dataArray[indexPath.section];
- NSMutableDictionary *dataCell = [NSMutableDictionary dictionaryWithDictionary:sectionArray[indexPath.row]];
- [dataCell setObject:indexPath forKey:kKeyIndexPath];
- return dataCell;
- }
- - (NSInteger)cellTypeAtIndexPath:(NSIndexPath *)indexPath {
- if (self.dataArray.count < indexPath.section ) {
- return -1;
- }
- NSArray *rowArray = self.dataArray[indexPath.section];
- NSDictionary *dataCell = [NSMutableDictionary dictionaryWithDictionary:rowArray[indexPath.row]];
- return dataCell[kKeyCellType]? [dataCell[kKeyCellType] integerValue] : -1;
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement