mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-23 20:31:13 +08:00
WIP on API improvements for RKForm
This commit is contained in:
@@ -63,7 +63,7 @@ typedef void(^RKFormBlock)();
|
||||
@property (nonatomic, readonly) NSArray *tableItems;
|
||||
|
||||
- (void)addSection:(RKFormSection *)section;
|
||||
- (void)addSectionUsingBlock:(void (^)(RKFormSection *section))block;
|
||||
- (void)addSectionUsingBlock:(void (^)(RKFormSection *section))block; // TODO: Eliminate this signature...
|
||||
|
||||
/** @name Single Section Forms */
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
@property (nonatomic, readonly) id object;
|
||||
|
||||
+ (id)sectionInForm:(RKForm *)form;
|
||||
+ (id)sectionUsingBlock:(void (^)(RKFormSection *))block;
|
||||
- (id)initWithForm:(RKForm *)form;
|
||||
|
||||
- (void)addTableItem:(RKTableItem *)tableItem;
|
||||
@@ -43,4 +44,6 @@
|
||||
- (void)addRowMappingAttribute:(NSString *)attributeKeyPath toKeyPath:(NSString *)cellKeyPath onCellWithClass:(Class)cellClass;
|
||||
- (void)addRowMappingAttribute:(NSString *)attributeKeyPath toKeyPath:(NSString *)cellKeyPath onCellWithClass:(Class)cellClass usingBlock:(void (^)(RKTableItem *tableItem))block;
|
||||
|
||||
- (void)addMappingFromAttribute:(NSString *)attributeKeyPath toKeyPath:(NSString *)keyPath forTableItem:(RKTableItem *)tableItem;
|
||||
|
||||
@end
|
||||
|
||||
@@ -29,8 +29,14 @@
|
||||
return [[[self alloc] initWithForm:form] autorelease];
|
||||
}
|
||||
|
||||
- (id)initWithForm:(RKForm *)form
|
||||
+ (id)sectionUsingBlock:(void (^)(RKFormSection *))block
|
||||
{
|
||||
RKFormSection *section = [self section];
|
||||
block(section);
|
||||
return section;
|
||||
}
|
||||
|
||||
- (id)initWithForm:(RKForm *)form {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.form = form;
|
||||
@@ -117,8 +123,26 @@
|
||||
[self addTableItem:tableItem];
|
||||
}
|
||||
|
||||
- (void)addRowMappingAttribute:(NSString *)attributeKeyPath toKeyPath:(NSString *)controlKeyPath onControl:(UIControl *)control usingBlock:(void (^)(RKControlTableItem *tableItem))block {
|
||||
- (void)addRowMappingAttribute:(NSString *)attributeKeyPath toKeyPath:(NSString *)controlKeyPath onControl:(UIControl *)control usingBlock:(void (^)(RKControlTableItem *tableItem))block
|
||||
{
|
||||
- (void)addMappingFromAttribute:(NSString *)attributeKeyPath toKeyPath:(NSString *)keyPath forTableItem:(RKTableItem *)tableItem {
|
||||
RKObjectAttributeMapping *attributeMapping = [[RKObjectAttributeMapping new] autorelease];
|
||||
attributeMapping.sourceKeyPath = [NSString stringWithFormat:@"userData.__RestKit__object.%@", attributeKeyPath];
|
||||
attributeMapping.destinationKeyPath = keyPath;
|
||||
|
||||
// TODO: This is duplicating code...
|
||||
[tableItem.cellMapping addAttributeMapping:attributeMapping];
|
||||
|
||||
// Use KVC storage to associate the table item with object being mapped
|
||||
// TODO: Move these to constants...
|
||||
[tableItem.userData setValue:self.object forKey:@"__RestKit__object"];
|
||||
[tableItem.userData setValue:attributeKeyPath forKey:@"__RestKit__attributeKeyPath"];
|
||||
[tableItem.userData setValue:attributeMapping forKey:@"__RestKit__attributeToControlMapping"];
|
||||
// [self addAttributeMapping:attributeMapping forKeyPath:attributeKeyPath toTableItem:tableItem];
|
||||
}
|
||||
|
||||
- (void)addRowMappingAttribute:(NSString *)attributeKeyPath toKeyPath:(NSString *)controlKeyPath onControl:(UIControl *)control usingBlock:(void (^)(RKControlTableItem *tableItem))block {
|
||||
RKControlTableItem *tableItem = [RKControlTableItem tableItemWithControl:control];
|
||||
RKObjectAttributeMapping *attributeMapping = [[RKObjectAttributeMapping new] autorelease];
|
||||
attributeMapping.sourceKeyPath = [NSString stringWithFormat:@"userData.__RestKit__object.%@", attributeKeyPath];
|
||||
|
||||
Reference in New Issue
Block a user