Skip to content

Commit

Permalink
Merge pull request #2 from DenHeadless/develop
Browse files Browse the repository at this point in the history
Simplify Nib mapping methods
  • Loading branch information
DenTelezhkin committed Oct 24, 2012
2 parents 811b84a + 4ca4c28 commit 732c039
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 25 deletions.
6 changes: 4 additions & 2 deletions DTTableViewController/DTCellFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ SYNTHESIZE_SINGLETON_FOR_CLASS_HEADER(DTCellFactory)
//

// Designated mapping method:
-(void)addCellClassMapping:(Class)cellClass forModelClass:(Class)modelClass;
-(void)setCellClassMapping:(Class)cellClass forModelClass:(Class)modelClass;

// For mapping custom NIB for cell, please call DTTableViewManager method.

// Dictionary should contain NSStringFromClass values and keys
-(void)addObjectMappingDictionary:(NSDictionary *)mappingDictionary;
-(void)setObjectMappingDictionary:(NSDictionary *)mappingDictionary;

@end
4 changes: 2 additions & 2 deletions DTTableViewController/DTCellFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ - (void)dealloc

#pragma mark - class mapping

- (void)addCellClassMapping:(Class)cellClass forModelClass:(Class)modelClass
- (void)setCellClassMapping:(Class)cellClass forModelClass:(Class)modelClass
{
[self.mappingsDictionary setObject:NSStringFromClass(cellClass)
forKey:NSStringFromClass(modelClass)];
}

- (void)addObjectMappingDictionary:(NSDictionary *)mappingDictionary
- (void)setObjectMappingDictionary:(NSDictionary *)mappingDictionary
{
[self.mappingsDictionary addEntriesFromDictionary:mappingDictionary];
}
Expand Down
15 changes: 13 additions & 2 deletions DTTableViewController/DTTableViewManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,19 @@
// Mapping
// redirect to CellFactory

-(void)addObjectMappingDictionary:(NSDictionary *)mapping;
-(void)addCellClassMapping:(Class)cellClass forModelClass:(Class)modelClass;
// Designated setters

// create your cells from code, or use standard cells:
-(void)setCellMappingforClass:(Class)cellClass modelClass:(Class)modelClass;

// create your custom cells from IB:
-(void)setCellMappingForNib:(NSString *)nibName
cellClass:(Class)cellClass
modelClass:(Class)modelClass;


// Not recommended, but you can do it if you like. Just take a look, how
// this is done in setCellClassMapping:forModelClass method
-(void)setObjectMappingDictionary:(NSDictionary *)mapping;

@end
16 changes: 12 additions & 4 deletions DTTableViewController/DTTableViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,23 @@ -(void)setSectionFooters:(NSArray *)footers

#pragma mark - mapping

-(void)addCellClassMapping:(Class)cellClass forModelClass:(Class)modelClass
-(void)setCellMappingforClass:(Class)cellClass modelClass:(Class)modelClass
{
[[DTCellFactory sharedInstance] addCellClassMapping:cellClass
[[DTCellFactory sharedInstance] setCellClassMapping:cellClass
forModelClass:modelClass];
}

-(void)addObjectMappingDictionary:(NSDictionary *)mapping
-(void)setCellMappingForNib:(NSString *)nibName cellClass:(Class)cellClass modelClass:(Class)modelClass
{
[[DTCellFactory sharedInstance] addObjectMappingDictionary:mapping];
[self.tableView registerNib:[UINib nibWithNibName:nibName bundle:nil]
forCellReuseIdentifier:NSStringFromClass([modelClass class])];

[self setCellMappingforClass:cellClass modelClass:modelClass];
}

-(void)setObjectMappingDictionary:(NSDictionary *)mapping
{
[[DTCellFactory sharedInstance] setObjectMappingDictionary:mapping];
}

#pragma mark - search
Expand Down
2 changes: 1 addition & 1 deletion Example/CedarUnitTests/DTCellFactorySpec.mm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import "DTCellFactory.h"
//#import "DTCellFactory.h"

using namespace Cedar::Matchers;
using namespace Cedar::Doubles;
Expand Down
2 changes: 1 addition & 1 deletion Example/CedarUnitTests/DTTableViewManagerSpec.mm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import "DTTableViewManager.h"
//#import "DTTableViewManager.h"
#import <Foundation/Foundation.h>

using namespace Cedar::Matchers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
[self addCellClassMapping:[ExampleCell class] forModelClass:[Example class]];
[self setCellMappingforClass:[ExampleCell class] modelClass:[Example class]];
}
return self;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {

[self addCellClassMapping:[CustomCell class] forModelClass:[CustomModel class]];

self.title = @"Custom NIB";

}
return self;
}
Expand All @@ -31,11 +27,10 @@ - (void)viewDidLoad
// Do any additional setup after loading the view from its nib.

// CustomCell is created from NIB
// IMPORTANT to register cell nib for reuse identifier IDENTICAL to your model class name
[self.tableView registerNib:[UINib nibWithNibName:@"CustomCell" bundle:nil]
forCellReuseIdentifier:@"CustomModel"];


[self setCellMappingForNib:@"CustomCell"
cellClass:[CustomCell class]
modelClass:[CustomModel class]];

[self addTableItem:[CustomModel modelWithText1:@"Very"
text2:@"Customized"
text3:@"Table"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {

[self addCellClassMapping:[ExampleCell class] forModelClass:[Example class]];
[self setCellMappingforClass:[ExampleCell class] modelClass:[Example class]];
}
return self;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
[self addCellClassMapping:[ExampleCell class] forModelClass:[Example class]];
[self setCellMappingforClass:[ExampleCell class] modelClass:[Example class]];
}
return self;
}
Expand Down
2 changes: 1 addition & 1 deletion Example/TableViewFactory/ExampleTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ -(DTTableViewManager *)tableManager
andTableView:self.tableView];

// Recommended to add mappings right here, in tableManager getter
[self.tableManager addCellClassMapping:[ExampleCell class] forModelClass:[Example class]];
[self.tableManager setCellMappingforClass:[ExampleCell class] modelClass:[Example class]];

// Uncomment this line if you want to NOT reuse cells.
// self.doNotReuseCells = YES;
Expand Down

0 comments on commit 732c039

Please sign in to comment.