Skip to content

Instantly share code, notes, and snippets.

@garrefa
Created March 24, 2015 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garrefa/1aed5b6dd9ec523b6b08 to your computer and use it in GitHub Desktop.
Save garrefa/1aed5b6dd9ec523b6b08 to your computer and use it in GitHub Desktop.
Exemplo de Datasource Aggregator usando no post UITableViewControllers com Máquina de Estados e Agregador de Delegates/Datasources.no blog da Concrete. blog.concretesolutions.com.br
//
// AgregadorTableViewDataSource.m
// DataSourceAggregator
//
// Created by Alexandre Garrefa on 3/24/15.
// Copyright (c) 2015 Concrete Solutions. All rights reserved.
//
#import "AgregadorTableViewDataSource.h"
#import "Passo01TableViewDataSource.h"
#import "Passo02TableViewDataSource.h"
#import "Passo03TableViewDataSource.h"
typedef NS_ENUM(NSUInteger, EstadosDaTabela) {
EstadoPasso1,
EstadoPasso2,
EstadoPasso3
};
@interface AgregadorTableViewDataSource ()
@property (nonatomic, assign) EstadosDaTabela estado;
@property (nonatomic, strong) Passo01TableViewDataSource *passo01DS;
@property (nonatomic, strong) Passo02TableViewDataSource *passo02DS;
@property (nonatomic, strong) Passo03TableViewDataSource *passo03DS;
@end
@implementation AgregadorTableViewDataSource
- (instancetype)init {
if(!(self = [super init])) return nil;
_estado = EstadoPasso1;
_passo01DS = [[Passo01TableViewDataSource alloc] init];
_passo02DS = [[Passo02TableViewDataSource alloc] init];
_passo03DS = [[Passo03TableViewDataSource alloc] init];
return self;
}
#pragma mark - Table View Data Source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
switch (self.estado) {
case EstadoPasso1:
return [_passo01DS numberOfSectionsInTableView:tableView];
case EstadoPasso2:
return [_passo02DS numberOfSectionsInTableView:tableView];
case EstadoPasso3:
return [_passo03DS numberOfSectionsInTableView:tableView];
default: return 0;
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
switch (self.estado) {
case EstadoPasso1:
return [_passo01DS tableView:tableView
numberOfRowsInSection:section];
case EstadoPasso2:
return [_passo02DS tableView:tableView
numberOfRowsInSection:section];
case EstadoPasso3:
return [_passo03DS tableView:tableView
numberOfRowsInSection:section];
default: return 0;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
switch (self.estado) {
case EstadoPasso1:
return [_passo01DS tableView:tableView
cellForRowAtIndexPath:indexPath];
case EstadoPasso2:
return [_passo02DS tableView:tableView
cellForRowAtIndexPath:indexPath];
case EstadoPasso3:
return [_passo03DS tableView:tableView
cellForRowAtIndexPath:indexPath];
default: return 0;
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment