diff --git a/DTTableViewController/DTCellFactory.h b/DTTableViewController/DTCellFactory.h index cae8a2ad..78c26cf3 100644 --- a/DTTableViewController/DTCellFactory.h +++ b/DTTableViewController/DTCellFactory.h @@ -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 diff --git a/DTTableViewController/DTCellFactory.m b/DTTableViewController/DTCellFactory.m index ab5a8926..e64e41a2 100644 --- a/DTTableViewController/DTCellFactory.m +++ b/DTTableViewController/DTCellFactory.m @@ -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]; } diff --git a/DTTableViewController/DTTableViewManager.h b/DTTableViewController/DTTableViewManager.h index 370d6d61..03819cd6 100644 --- a/DTTableViewController/DTTableViewManager.h +++ b/DTTableViewController/DTTableViewManager.h @@ -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 diff --git a/DTTableViewController/DTTableViewManager.m b/DTTableViewController/DTTableViewManager.m index 9c28b22b..10cf498b 100644 --- a/DTTableViewController/DTTableViewManager.m +++ b/DTTableViewController/DTTableViewManager.m @@ -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 diff --git a/Example/CedarUnitTests/DTCellFactorySpec.mm b/Example/CedarUnitTests/DTCellFactorySpec.mm index 86e161ac..59de12bf 100644 --- a/Example/CedarUnitTests/DTCellFactorySpec.mm +++ b/Example/CedarUnitTests/DTCellFactorySpec.mm @@ -1,4 +1,4 @@ -#import "DTCellFactory.h" +//#import "DTCellFactory.h" using namespace Cedar::Matchers; using namespace Cedar::Doubles; diff --git a/Example/CedarUnitTests/DTTableViewManagerSpec.mm b/Example/CedarUnitTests/DTTableViewManagerSpec.mm index c398d141..57d6ca06 100644 --- a/Example/CedarUnitTests/DTTableViewManagerSpec.mm +++ b/Example/CedarUnitTests/DTTableViewManagerSpec.mm @@ -1,4 +1,4 @@ -#import "DTTableViewManager.h" +//#import "DTTableViewManager.h" #import using namespace Cedar::Matchers; diff --git a/Example/TableViewFactory/ExampleControllers/AddRemoveTableViewController.m b/Example/TableViewFactory/ExampleControllers/AddRemoveTableViewController.m index 1c26e069..fa5d390f 100644 --- a/Example/TableViewFactory/ExampleControllers/AddRemoveTableViewController.m +++ b/Example/TableViewFactory/ExampleControllers/AddRemoveTableViewController.m @@ -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; } diff --git a/Example/TableViewFactory/ExampleControllers/CustomCellsTableViewController.m b/Example/TableViewFactory/ExampleControllers/CustomCellsTableViewController.m index d595cb8a..6546213c 100644 --- a/Example/TableViewFactory/ExampleControllers/CustomCellsTableViewController.m +++ b/Example/TableViewFactory/ExampleControllers/CustomCellsTableViewController.m @@ -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; } @@ -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" diff --git a/Example/TableViewFactory/ExampleControllers/InsertReplaceTableViewController.m b/Example/TableViewFactory/ExampleControllers/InsertReplaceTableViewController.m index 245e89be..e48ee7ab 100644 --- a/Example/TableViewFactory/ExampleControllers/InsertReplaceTableViewController.m +++ b/Example/TableViewFactory/ExampleControllers/InsertReplaceTableViewController.m @@ -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; } diff --git a/Example/TableViewFactory/ExampleControllers/ReorderTableViewController.m b/Example/TableViewFactory/ExampleControllers/ReorderTableViewController.m index 3d58812d..46f7e39b 100644 --- a/Example/TableViewFactory/ExampleControllers/ReorderTableViewController.m +++ b/Example/TableViewFactory/ExampleControllers/ReorderTableViewController.m @@ -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; } diff --git a/Example/TableViewFactory/ExampleTableViewController.m b/Example/TableViewFactory/ExampleTableViewController.m index 71328ce7..7bcb4822 100644 --- a/Example/TableViewFactory/ExampleTableViewController.m +++ b/Example/TableViewFactory/ExampleTableViewController.m @@ -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;