Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ - (id)init
row.selectorOptions = @[@"Option 1", @"Option 2", @"Option 3"];
section.multivaluedRowTemplate = [row copy];
[section addFormRow:row];


// Add Section Button
section = [XLFormSectionDescriptor formSection];
[form addFormSection:section];
row = [XLFormRowDescriptor formRowDescriptorWithTag:@"AddSectionButton" rowType:XLFormRowDescriptorTypeButton title:@"Add Section"];
row.action.formSelector = @selector(didTouchAddSectionButton:);
[row.cellConfigAtConfigure setObject:[UIColor clearColor] forKey:@"backgroundColor"];
[row.cellConfig setObject:[UIColor grayColor] forKey:@"textLabel.color"];
[row.cellConfig setObject:[UIFont fontWithName:@"Helvetica" size:17] forKey:@"textLabel.font"];
[section addFormRow:row];

return [super initWithForm:form];
}

Expand All @@ -90,6 +102,25 @@ -(void)addDidTouch:(UIBarButtonItem * __unused)sender

}

-(void)didTouchAddSectionButton:(XLFormRowDescriptor *)sender
{
// Create a new section
XLFormSectionDescriptor * newSection = [XLFormSectionDescriptor formSectionWithTitle:[NSString stringWithFormat:@"Section created at %@", [NSDateFormatter localizedStringFromDate:[NSDate new] dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterShortStyle]]];
newSection.multivaluedTag = [NSString stringWithFormat:@"multivaluedPushSelector_%@", @(self.form.formSections.count-1)];

// Add rows to the new section
XLFormRowDescriptor * newRow = [XLFormRowDescriptor formRowDescriptorWithTag:nil rowType:XLFormRowDescriptorTypeSelectorPush title:@"Language"];
newRow.selectorOptions = @[@"Option 1", @"Option 2", @"Option 3"];
[newSection addFormRow:newRow];
newRow = [XLFormRowDescriptor formRowDescriptorWithTag:nil rowType:XLFormRowDescriptorTypeSelectorPush title:@"Level"];
newRow.selectorOptions = @[@"Option A", @"Option B", @"Option C"];
[newSection addFormRow:newRow];

// Add new section
[self.form addFormSection:newSection beforeSection:sender.sectionDescriptor];
[self deselectFormRow:sender];
}

#pragma mark - UIActionSheetDelegate

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
Expand All @@ -116,6 +147,7 @@ - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger
}
}


@end


Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -900,9 +900,9 @@ Version 3.0.0 (master)
* `hidden` property added to `XLFormSectionDescriptor`. `@YES` `@NO` or a `NSPredicate` can be used to hide the section.
* Added `XLFormRowDescriptorTypeCountDownTimerInline` and `XLFormRowDescriptorTypeCountDownTimer` row type with an example.
* Deleted `dateFormatter` property and added support to use the `NSValueTransformer` to convert the selected object to a NSString in the XLFormDateCell class.

* Added `XLFormRowDescriptorTypeCountDownTimerInline` and `XLFormRowDescriptorTypeCountDownTimer` row type with an example.
* Deleted `dateFormatter` property and added support to use the `NSValueTransformer` to convert the selected object to a NSString in the XLFormDateCell class.
* Added example in the ```Multivalued Sections examples``` of how to add dynamic sections with multiple rows.


Version 2.2.0
Expand Down
1 change: 1 addition & 0 deletions XLForm/XL/Descriptors/XLFormDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ typedef NS_OPTIONS(NSUInteger, XLFormRowNavigationOptions) {

-(void)addFormSection:(XLFormSectionDescriptor *)formSection;
-(void)addFormSection:(XLFormSectionDescriptor *)formSection atIndex:(NSUInteger)index;
-(void)addFormSection:(XLFormSectionDescriptor *)formSection beforeSection:(XLFormSectionDescriptor *)beforeSection;
-(void)addFormSection:(XLFormSectionDescriptor *)formSection afterSection:(XLFormSectionDescriptor *)afterSection;
-(void)addFormRow:(XLFormRowDescriptor *)formRow beforeRow:(XLFormRowDescriptor *)afterRow;
-(void)addFormRow:(XLFormRowDescriptor *)formRow beforeRowTag:(NSString *)afterRowTag;
Expand Down
17 changes: 17 additions & 0 deletions XLForm/XL/Descriptors/XLFormDescriptor.m
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,23 @@ -(void)addFormSection:(XLFormSectionDescriptor *)formSection afterSection:(XLFor
formSection.hidden = formSection.hidden;
}

-(void)addFormSection:(XLFormSectionDescriptor *)formSection beforeSection:(XLFormSectionDescriptor *)afterSection
{
NSUInteger sectionIndex;
NSUInteger allSectionIndex;
if ((sectionIndex = [self.allSections indexOfObject:formSection]) == NSNotFound){
allSectionIndex = [self.allSections indexOfObject:afterSection];
if (allSectionIndex != NSNotFound) {
[self insertObject:formSection inAllSectionsAtIndex:allSectionIndex];
}
else { //case when afterSection does not exist. Just insert at the end.
[self addFormSection:formSection];
return;
}
}
formSection.hidden = formSection.hidden;
}


-(void)addFormRow:(XLFormRowDescriptor *)formRow beforeRow:(XLFormRowDescriptor *)beforeRow
{
Expand Down