Skip to content

Commit

Permalink
[FormMapping] custom text controller
Browse files Browse the repository at this point in the history
  • Loading branch information
brunow committed Jun 15, 2012
1 parent 1386af2 commit 80dba3d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
1 change: 1 addition & 0 deletions Code/FormMapping/BKFormAttributeMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ typedef enum {
@property (nonatomic, copy) BKFormMappingCellSelectionBlock cellSelectionBlock;
@property (nonatomic, assign) Class customCell;
@property (nonatomic, assign) CGFloat rowHeight;
@property (nonatomic, assign) Class controllerClass;

/*
* Convenient method to get an attributeMapping
Expand Down
1 change: 1 addition & 0 deletions Code/FormMapping/BKFormAttributeMapping.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ @implementation BKFormAttributeMapping
@synthesize cellSelectionBlock = _cellSelectionBlock;
@synthesize customCell = _customCell;
@synthesize rowHeight = _rowHeight;
@synthesize controllerClass = _controllerClass;


////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
9 changes: 5 additions & 4 deletions Code/FormMapping/BKFormMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
title:(NSString *)title
type:(BKFormAttributeMappingType)type;

- (void)mapAttribute:(NSString *)attribute
title:(NSString *)title
type:(BKFormAttributeMappingType)type
controllerClass:(Class)controllerClass;

- (void)mapAttribute:(NSString *)attribute
title:(NSString *)title
type:(BKFormAttributeMappingType)type
Expand All @@ -69,10 +74,6 @@ valueFromSelectBlock:(BKFormMappingValueFromSelectBlock)valueFromSelectBlock
willDisplayCellBlock:(BKFormMappingWillDisplayCellBlock)willDisplayCellBlock
didSelectBlock:(BKFormMappingCellSelectionBlock)selectionBlock;

//[formMapping mapCustomCell:[UITableViewCell class] identidier:@"customCell" willDisplayCellBlock:^UITableViewCell *(id object, NSIndexPath *indexPath, UITableViewCell *cell) {
// cell.textLabel.text = @"It's a custom cell";
//}];

- (void)sectiontTitle:(NSString *)title identifier:(NSString *)identifier;

- (void)button:(NSString *)title
Expand Down
17 changes: 12 additions & 5 deletions Code/FormMapping/BKFormMapping.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@ - (void)mapAttribute:(NSString *)attribute

////////////////////////////////////////////////////////////////////////////////////////////////////
- (void)mapAttribute:(NSString *)attribute title:(NSString *)title {
BKFormAttributeMapping *attributeMapping = [BKFormAttributeMapping attributeMapping];
attributeMapping.title = title;
attributeMapping.attribute = attribute;

[self addAttributeMappingToFormMapping:attributeMapping];
[self mapAttribute:attribute title:title type:BKFormAttributeMappingTypeDefault];
}


Expand All @@ -107,10 +103,21 @@ - (void)mapAttribute:(NSString *)attribute
title:(NSString *)title
type:(BKFormAttributeMappingType)type {

[self mapAttribute:attribute title:title type:type controllerClass:nil];
}


////////////////////////////////////////////////////////////////////////////////////////////////////
- (void)mapAttribute:(NSString *)attribute
title:(NSString *)title
type:(BKFormAttributeMappingType)type
controllerClass:(Class)controllerClass {

BKFormAttributeMapping *attributeMapping = [BKFormAttributeMapping attributeMapping];
attributeMapping.title = title;
attributeMapping.attribute = attribute;
attributeMapping.type = type;
attributeMapping.controllerClass = controllerClass;

[self addAttributeMappingToFormMapping:attributeMapping];
}
Expand Down
5 changes: 4 additions & 1 deletion Code/FormMapping/BKFormModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,11 @@ - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
- (void)showTextViewControllerWithAttributeMapping:(BKFormAttributeMapping *)attributeMapping {
BK_WEAK_IVAR BKFormModel *weakRef = self;
[self.navigationController pushViewControllerWithBlock:^UIViewController *{
Class controllerClass = (attributeMapping.controllerClass == nil) ?
[BWLongTextViewController class] : attributeMapping.controllerClass;

NSString *value = [self.formMapper valueForAttriteMapping:attributeMapping];
BWLongTextViewController *vc = [[BWLongTextViewController alloc] initWithText:value];
BWLongTextViewController *vc = [[controllerClass alloc] initWithText:value];
vc.title = attributeMapping.title;
vc.textView.delegate = weakRef.formMapper;
vc.textView.formAttributeMapping = attributeMapping;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#import "Movie.h"
#import "Comment.h"
#import "Genre.h"
#import "BWLongTextViewController.h"

@implementation FormTableViewExampleController

Expand Down Expand Up @@ -50,7 +51,7 @@ - (void)viewDidLoad {

[BKFormMapping mappingForClass:[Movie class] block:^(BKFormMapping *formMapping) {
[formMapping sectiontTitle:@"Information section" identifier:@"info"];
[formMapping mapAttribute:@"title" title:@"Title" type:BKFormAttributeMappingTypeText];
[formMapping mapAttribute:@"title" title:@"Title" type:BKFormAttributeMappingTypeText controllerClass:[BWLongTextViewController class]];
[formMapping mapAttribute:@"releaseDate" title:@"ReleaseDate" type:BKFormAttributeMappingTypeDatePicker dateFormat:@"yyyy-MM-dd HH:mm:ss"];
[formMapping mapAttribute:@"suitAllAges" title:@"All ages" type:BKFormAttributeMappingTypeBoolean];
[formMapping mapAttribute:@"shortName" title:@"ShortName" type:BKFormAttributeMappingTypeLabel];
Expand Down

0 comments on commit 80dba3d

Please sign in to comment.