diff --git a/XLForm/XL/Cell/XLFormLeftRightSelectorCell.m b/XLForm/XL/Cell/XLFormLeftRightSelectorCell.m index a5db289c..f68590c0 100644 --- a/XLForm/XL/Cell/XLFormLeftRightSelectorCell.m +++ b/XLForm/XL/Cell/XLFormLeftRightSelectorCell.m @@ -156,6 +156,7 @@ -(void)formDescriptorCellDidSelectedWithFormController:(XLFormViewController *)c if (option.rightOptions){ XLFormOptionsViewController * optionsViewController = [[XLFormOptionsViewController alloc] initWithStyle:UITableViewStyleGrouped]; optionsViewController.title = option.selectorTitle; + optionsViewController.tableView.tintColor = self.rowDescriptor.selectorOptionsTintColor; optionsViewController.rowDescriptor = self.rowDescriptor; [controller.navigationController pushViewController:optionsViewController animated:YES]; } diff --git a/XLForm/XL/Cell/XLFormSelectorCell.m b/XLForm/XL/Cell/XLFormSelectorCell.m index 6bed8e08..4c83b571 100644 --- a/XLForm/XL/Cell/XLFormSelectorCell.m +++ b/XLForm/XL/Cell/XLFormSelectorCell.m @@ -192,7 +192,14 @@ -(void)formDescriptorCellDidSelectedWithFormController:(XLFormViewController *)c XLFormOptionsViewController * optionsViewController = [[XLFormOptionsViewController alloc] initWithStyle:UITableViewStyleGrouped titleHeaderSection:nil titleFooterSection:nil]; optionsViewController.rowDescriptor = self.rowDescriptor; optionsViewController.title = self.rowDescriptor.selectorTitle; - + optionsViewController.tableView.tintColor = self.rowDescriptor.selectorOptionsTintColor; + optionsViewController.editingOptionsEnabled = self.rowDescriptor.selectorOptionsEditingEnabled; + if (self.rowDescriptor.selectorOptionsEditingEnabled) { + NSAssert(![self.rowDescriptor.selectorOptionsAddNewOptionTitle isEqualToString:@""], @"selectorOptionsAddNewOptionTitle string must not be empty when selectorOptionsEditingEnabled is true"); + optionsViewController.editingOptionsAddNewOptionTitle = self.rowDescriptor.selectorOptionsAddNewOptionTitle; + NSAssert(![self.rowDescriptor.selectorOptionsNewTextForOptionTitle isEqualToString:@""], @"selectorOptionsNewTextForOptionTitle string must not be empty when selectorOptionsEditingEnabled is true"); + optionsViewController.editingOptionsNewTextForOptionTitle = self.rowDescriptor.selectorOptionsNewTextForOptionTitle; + } if ([self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeSelectorPopover]) { self.popoverController = [[UIPopoverController alloc] initWithContentViewController:optionsViewController]; self.popoverController.delegate = self; @@ -211,11 +218,20 @@ -(void)formDescriptorCellDidSelectedWithFormController:(XLFormViewController *)c } else if ([self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeMultipleSelector] || [self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeMultipleSelectorPopover]) { - NSAssert(self.rowDescriptor.selectorOptions, @"selectorOptions property shopuld not be nil"); + NSAssert(self.rowDescriptor.selectorOptions, @"selectorOptions property should not be nil"); XLFormOptionsViewController * optionsViewController = [[XLFormOptionsViewController alloc] initWithStyle:UITableViewStyleGrouped titleHeaderSection:nil titleFooterSection:nil]; optionsViewController.rowDescriptor = self.rowDescriptor; optionsViewController.title = self.rowDescriptor.selectorTitle; - + optionsViewController.tableView.tintColor = self.rowDescriptor.selectorOptionsTintColor; + if ([self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeMultipleSelector]) { + optionsViewController.editingOptionsEnabled = self.rowDescriptor.selectorOptionsEditingEnabled; + if (self.rowDescriptor.selectorOptionsEditingEnabled) { + NSAssert(![self.rowDescriptor.selectorOptionsAddNewOptionTitle isEqualToString:@""], @"selectorOptionsAddNewOptionTitle string must not be empty when selectorOptionsEditingEnabled is true"); + optionsViewController.editingOptionsAddNewOptionTitle = self.rowDescriptor.selectorOptionsAddNewOptionTitle; + NSAssert(![self.rowDescriptor.selectorOptionsNewTextForOptionTitle isEqualToString:@""], @"selectorOptionsNewTextForOptionTitle string must not be empty when selectorOptionsEditingEnabled is true"); + optionsViewController.editingOptionsNewTextForOptionTitle = self.rowDescriptor.selectorOptionsNewTextForOptionTitle; + } + } if ([self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeMultipleSelectorPopover]) { self.popoverController = [[UIPopoverController alloc] initWithContentViewController:optionsViewController]; self.popoverController.delegate = self; diff --git a/XLForm/XL/Controllers/XLFormOptionsViewController.h b/XLForm/XL/Controllers/XLFormOptionsViewController.h index 66b03eb1..bf1032f6 100644 --- a/XLForm/XL/Controllers/XLFormOptionsViewController.h +++ b/XLForm/XL/Controllers/XLFormOptionsViewController.h @@ -37,5 +37,8 @@ titleHeaderSection:(NSString *)titleHeaderSection titleFooterSection:(NSString *)titleFooterSection; +@property (getter=isEditingEnabled, nonatomic) BOOL editingOptionsEnabled; +@property (nonatomic) NSString *editingOptionsNewTextForOptionTitle; +@property (nonatomic) NSString *editingOptionsAddNewOptionTitle; @end diff --git a/XLForm/XL/Controllers/XLFormOptionsViewController.m b/XLForm/XL/Controllers/XLFormOptionsViewController.m index 3404a9ec..b08013fd 100644 --- a/XLForm/XL/Controllers/XLFormOptionsViewController.m +++ b/XLForm/XL/Controllers/XLFormOptionsViewController.m @@ -74,29 +74,252 @@ - (void)viewDidLoad [self.tableView registerClass:[XLFormRightDetailCell class] forCellReuseIdentifier:CELL_REUSE_IDENTIFIER]; } +- (void)setEditingOptionsEnabled:(BOOL)editingOptionsEnabled +{ + _editingOptionsEnabled = editingOptionsEnabled; + if (self.rowDescriptor.rowType == XLFormRowDescriptorTypeSelectorLeftRight){ + // not handled yet + NSAssert(editingOptionsEnabled, @"Editing selector options is currently not allowed for XLFormRowDescriptorTypeSelectorLeftRight row types."); + } else { + // add edit button + if (editingOptionsEnabled) { + self.navigationItem.rightBarButtonItem = self.editButtonItem; + } + } +} + +- (void)setEditing:(BOOL)editing animated:(BOOL)animated +{ + if (self.rowDescriptor.rowType == XLFormRowDescriptorTypeSelectorLeftRight){ + // not handled yet + NSAssert(editing, @"Editing selector options is currently not allowed for XLFormRowDescriptorTypeSelectorLeftRight row types."); + } else { + [super setEditing:editing animated:animated]; + + [self.tableView setEditing:editing animated:YES]; + + // allow cell selection when editing + [self.tableView setAllowsSelectionDuringEditing:YES]; + + // reload table to show the "add new" row + [self.tableView reloadData]; + } +} + +- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath +{ + if (self.rowDescriptor.rowType == XLFormRowDescriptorTypeSelectorLeftRight){ + // not handled yet + } else { + // avoid moving "add new" row + if (indexPath.row > 0) { + return YES; + } + } + return NO; +} + +- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { + if (self.rowDescriptor.rowType == XLFormRowDescriptorTypeSelectorLeftRight){ + // not handled yet + } else { + return YES; + } + return NO; +} + +- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath +{ + if (self.rowDescriptor.rowType == XLFormRowDescriptorTypeSelectorLeftRight){ + // not handled yet + } else { + if (sourceIndexPath.row != destinationIndexPath.row) { + // retrieve selector options + NSMutableArray *selectorOptions = [[self selectorOptions] mutableCopy]; + id sourceCellObject = [[self selectorOptions] objectAtIndex:sourceIndexPath.row - 1]; // ignore "add new" row + // move selector option from source to destination row + [selectorOptions removeObjectAtIndex:sourceIndexPath.row - 1]; + [selectorOptions insertObject:sourceCellObject atIndex:destinationIndexPath.row -1]; // ignore "add new" row + // update selector options + self.rowDescriptor.selectorOptions = selectorOptions; + // callback + [self.rowDescriptor optionsViewControllerDidSortSelectorOption:sourceCellObject fromPosition:(int)sourceIndexPath.row toPosition:(int)destinationIndexPath.row]; + } + } +} #pragma mark - UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + if (self.rowDescriptor.rowType == XLFormRowDescriptorTypeSelectorLeftRight){ + // not handled yet + } else { + return self.editing ? [[self selectorOptions] count] + 1 : [[self selectorOptions] count]; + } return [[self selectorOptions] count]; } +- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath +{ + if (self.rowDescriptor.rowType == XLFormRowDescriptorTypeSelectorLeftRight){ + // not handled yet + } else { + return indexPath.row > 0 ? UITableViewCellEditingStyleDelete : UITableViewCellEditingStyleInsert; + } + return UITableViewCellEditingStyleNone; +} + +- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath +{ + if (self.rowDescriptor.rowType == XLFormRowDescriptorTypeSelectorLeftRight){ + // not handled yet + } else { + if (editingStyle == UITableViewCellEditingStyleInsert) { + + UIAlertController *alert = [UIAlertController alertControllerWithTitle:self.editingOptionsAddNewOptionTitle + message:nil + preferredStyle:UIAlertControllerStyleAlert]; + // add textfield showing old option text + [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { + textField.keyboardType = UIKeyboardTypeAlphabet; + textField.autocapitalizationType = UITextAutocapitalizationTypeWords; + textField.placeholder = @"Enter text"; + }]; + + // ok action performs change of option text + UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" + style:UIAlertActionStyleDefault + handler:^(UIAlertAction *action) { + UITextField *textField = [alert.textFields firstObject]; + if (![textField.text isEqualToString:@""]) { + NSLog(@"option text changed to %@", textField.text); + + // create new option with new text + id newOption = [XLFormOptionsObject formOptionsObjectWithValue:@(-1) displayText:textField.text]; + + // replace option at the bottom + NSMutableArray *selectorOptions = [[self selectorOptions] mutableCopy]; + [selectorOptions addObject:newOption]; + + // change row selector options + self.rowDescriptor.selectorOptions = selectorOptions; + + // callback + [self.rowDescriptor optionsViewControllerDidAddSelectorOption:newOption]; + + // reload table + [self.tableView reloadData]; + } + }]; + [alert addAction:okAction]; + + // cancel action does nothing + UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" + style:UIAlertActionStyleDefault + handler:nil]; + [alert addAction:cancelAction]; + + // show alert + [self presentViewController:alert animated:YES completion:nil]; + + } else if (editingStyle == UITableViewCellEditingStyleDelete) { + // retrieve selector options + NSMutableArray *selectorOptions = [[self selectorOptions] mutableCopy]; + + if ([selectorOptions count] > 1) { + id cellObject = [[self selectorOptions] objectAtIndex:indexPath.row - 1]; // ignore "add new" row + + // move selector option from source to destination row + [selectorOptions removeObjectAtIndex:indexPath.row - 1]; + + // update selector options + self.rowDescriptor.selectorOptions = selectorOptions; + + // callback + [self.rowDescriptor optionsViewControllerDidDeleteSelectorOption:cellObject]; + + // reload table + [self.tableView reloadData]; + + } else { + // avoid deleting last selector option + UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" + message:@"Can't delete last option. Add another option and then try again." + preferredStyle:UIAlertControllerStyleAlert]; + // ok action does nothing + UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" + style:UIAlertActionStyleDefault + handler:nil]; + [alert addAction:okAction]; + + // show alert + [self presentViewController:alert animated:YES completion:nil]; + + // reload table + [self.tableView reloadData]; + } + + } + } +} + +- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath +{ + if (self.rowDescriptor.rowType == XLFormRowDescriptorTypeSelectorLeftRight){ + // not handled yet + } else { + // avoid targeting "add new" row + if (proposedDestinationIndexPath.row == 0) { + return sourceIndexPath; + } + } + return proposedDestinationIndexPath; +} + +- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + if (self.editing) { + // avoid editing "add new" row + return indexPath.row == 0 ? nil : indexPath; + } + return indexPath; +} + - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { XLFormRightDetailCell * cell = [tableView dequeueReusableCellWithIdentifier:CELL_REUSE_IDENTIFIER forIndexPath:indexPath]; - id cellObject = [[self selectorOptions] objectAtIndex:indexPath.row]; - cell.textLabel.text = [self valueDisplayTextForOption:cellObject]; - if ([self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeMultipleSelector] || [self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeMultipleSelectorPopover]){ - cell.accessoryType = ([self selectedValuesContainsOption:cellObject] ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone); - } - else{ - if ([[self.rowDescriptor.value valueData] isEqual:[cellObject valueData]]){ - cell.accessoryType = UITableViewCellAccessoryCheckmark; + + if (self.editing) { + + NSAssert(self.rowDescriptor.rowType != XLFormRowDescriptorTypeSelectorLeftRight, @"Editing selector options is currently not allowed for XLFormRowDescriptorTypeSelectorLeftRight row types."); + + if (indexPath.row == 0) { + cell.textLabel.text = @"Add new"; + cell.editingAccessoryType = UITableViewCellAccessoryNone; + } else { + id cellObject = [[self selectorOptions] objectAtIndex:indexPath.row - 1]; + cell.textLabel.text = [self valueDisplayTextForOption:cellObject]; + cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator; } - else{ - cell.accessoryType = UITableViewCellAccessoryNone; + cell.accessoryType = UITableViewCellAccessoryNone; + } else { + id cellObject = [[self selectorOptions] objectAtIndex:indexPath.row]; + cell.textLabel.text = [self valueDisplayTextForOption:cellObject]; + if ([self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeMultipleSelector] || [self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeMultipleSelectorPopover]){ + cell.accessoryType = ([self selectedValuesContainsOption:cellObject] ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone); + } + else { + if ([[self.rowDescriptor.value valueData] isEqual:[cellObject valueData]]){ + cell.accessoryType = UITableViewCellAccessoryCheckmark; + } + else{ + cell.accessoryType = UITableViewCellAccessoryNone; + } } + + cell.editingAccessoryType = UITableViewCellAccessoryNone; + } return cell; } @@ -114,52 +337,110 @@ - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInte #pragma mark - UITableViewDelegate - - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; - id cellObject = [[self selectorOptions] objectAtIndex:indexPath.row]; - if ([self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeMultipleSelector] || [self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeMultipleSelectorPopover]){ - if ([self selectedValuesContainsOption:cellObject]){ - self.rowDescriptor.value = [self selectedValuesRemoveOption:cellObject]; - cell.accessoryType = UITableViewCellAccessoryNone; - } - else{ - self.rowDescriptor.value = [self selectedValuesAddOption:cellObject]; - cell.accessoryType = UITableViewCellAccessoryCheckmark; - } - } - else{ - if ([[self.rowDescriptor.value valueData] isEqual:[cellObject valueData]]){ - if (!self.rowDescriptor.required){ - self.rowDescriptor.value = nil; + + if (self.editing) { + + NSAssert(self.rowDescriptor.rowType != XLFormRowDescriptorTypeSelectorLeftRight, @"Editing selector options is currently not allowed for XLFormRowDescriptorTypeSelectorLeftRight row types."); + + id cellObject = [[self selectorOptions] objectAtIndex:indexPath.row - 1]; // ignore "add new" row + + UIAlertController *alert = [UIAlertController alertControllerWithTitle:self.editingOptionsNewTextForOptionTitle + message:nil + preferredStyle:UIAlertControllerStyleAlert]; + // add textfield showing old option text + [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { + textField.keyboardType = UIKeyboardTypeAlphabet; + textField.autocapitalizationType = UITextAutocapitalizationTypeWords; + textField.text = [cellObject displayText]; + textField.placeholder = @"Enter text"; + }]; + + // ok action performs change of option text + UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" + style:UIAlertActionStyleDefault + handler:^(UIAlertAction *action) { + UITextField *textField = [alert.textFields firstObject]; + if (![textField.text isEqualToString:@""]) { + NSLog(@"option text changed to %@", textField.text); + + // create new option with new text + id newOption = [XLFormOptionsObject formOptionsObjectWithValue:[cellObject valueData] displayText:textField.text]; + + // replace option + NSMutableArray *selectorOptions = [[self selectorOptions] mutableCopy]; + [selectorOptions replaceObjectAtIndex:indexPath.row-1 withObject:newOption]; + + // change row selector options + self.rowDescriptor.selectorOptions = selectorOptions; + + // reload table + [self.tableView reloadData]; + + // callback + [self.rowDescriptor optionsViewControllerDidChangeSelectorOption:cellObject newText:textField.text]; + } + }]; + [alert addAction:okAction]; + + // cancel action does nothing + UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" + style:UIAlertActionStyleDefault + handler:nil]; + [alert addAction:cancelAction]; + + // show alert + [self presentViewController:alert animated:YES completion:nil]; + + + } else { + + id cellObject = [[self selectorOptions] objectAtIndex:indexPath.row]; + + if ([self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeMultipleSelector] || [self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeMultipleSelectorPopover]){ + if ([self selectedValuesContainsOption:cellObject]){ + self.rowDescriptor.value = [self selectedValuesRemoveOption:cellObject]; + cell.accessoryType = UITableViewCellAccessoryNone; + } + else{ + self.rowDescriptor.value = [self selectedValuesAddOption:cellObject]; + cell.accessoryType = UITableViewCellAccessoryCheckmark; } - cell.accessoryType = UITableViewCellAccessoryNone; } else{ - if (self.rowDescriptor.value){ - NSInteger index = [[self selectorOptions] formIndexForItem:self.rowDescriptor.value]; - if (index != NSNotFound){ - NSIndexPath * oldSelectedIndexPath = [NSIndexPath indexPathForRow:index inSection:0]; - UITableViewCell *oldSelectedCell = [tableView cellForRowAtIndexPath:oldSelectedIndexPath]; - oldSelectedCell.accessoryType = UITableViewCellAccessoryNone; + if ([[self.rowDescriptor.value valueData] isEqual:[cellObject valueData]]){ + if (!self.rowDescriptor.required){ + self.rowDescriptor.value = nil; } + cell.accessoryType = UITableViewCellAccessoryNone; + } + else{ + if (self.rowDescriptor.value){ + NSInteger index = [[self selectorOptions] formIndexForItem:self.rowDescriptor.value]; + if (index != NSNotFound){ + NSIndexPath * oldSelectedIndexPath = [NSIndexPath indexPathForRow:index inSection:0]; + UITableViewCell *oldSelectedCell = [tableView cellForRowAtIndexPath:oldSelectedIndexPath]; + oldSelectedCell.accessoryType = UITableViewCellAccessoryNone; + } + } + self.rowDescriptor.value = cellObject; + cell.accessoryType = UITableViewCellAccessoryCheckmark; + } + if (self.popoverController){ + [self.popoverController dismissPopoverAnimated:YES]; + [self.popoverController.delegate popoverControllerDidDismissPopover:self.popoverController]; + } + else if ([self.parentViewController isKindOfClass:[UINavigationController class]]){ + [self.navigationController popViewControllerAnimated:YES]; } - self.rowDescriptor.value = cellObject; - cell.accessoryType = UITableViewCellAccessoryCheckmark; - } - if (self.popoverController){ - [self.popoverController dismissPopoverAnimated:YES]; - [self.popoverController.delegate popoverControllerDidDismissPopover:self.popoverController]; - } - else if ([self.parentViewController isKindOfClass:[UINavigationController class]]){ - [self.navigationController popViewControllerAnimated:YES]; } } [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; } -#pragma mark - Helper +#pragma mark - Helpers -(NSMutableArray *)selectedValues { @@ -210,8 +491,6 @@ -(NSString *)valueDisplayTextForOption:(id)option return [option displayText]; } -#pragma mark - Helpers - -(NSArray *)selectorOptions { if (self.rowDescriptor.rowType == XLFormRowDescriptorTypeSelectorLeftRight){ diff --git a/XLForm/XL/Controllers/XLFormViewController.m b/XLForm/XL/Controllers/XLFormViewController.m index 1ab66f2b..841f44d0 100755 --- a/XLForm/XL/Controllers/XLFormViewController.m +++ b/XLForm/XL/Controllers/XLFormViewController.m @@ -314,6 +314,26 @@ -(void)formRowDescriptorPredicateHasChanged:(XLFormRowDescriptor *)formRow oldVa } } +- (void)formRowDescriptor:(nonnull XLFormRowDescriptor *)formRow didAddSelectorOption:(nonnull id)option +{ + [self updateAfterDependentRowChanged:formRow]; +} + +- (void)formRowDescriptor:(nonnull XLFormRowDescriptor *)formRow didDeleteSelectorOption:(nonnull id)option +{ + [self updateAfterDependentRowChanged:formRow]; +} + +- (void)formRowDescriptor:(nonnull XLFormRowDescriptor *)formRow didChangeSelectorOption:(nonnull id)option newText:(nonnull NSString *)newText +{ + [self updateAfterDependentRowChanged:formRow]; +} + +- (void)formRowDescriptor:(nonnull XLFormRowDescriptor *)formRow didSortSelectorOption:(nonnull id)option fromPosition:(int)fromPosition toPosition:(int)toPosition +{ + [self updateAfterDependentRowChanged:formRow]; +} + -(void)updateAfterDependentRowChanged:(XLFormRowDescriptor *)formRow { NSMutableArray* revaluateHidden = self.form.rowObservers[[formRow.tag formKeyForPredicateType:XLPredicateTypeHidden]]; diff --git a/XLForm/XL/Descriptors/XLFormDescriptorDelegate.h b/XLForm/XL/Descriptors/XLFormDescriptorDelegate.h index 69e0a827..93ce528c 100644 --- a/XLForm/XL/Descriptors/XLFormDescriptorDelegate.h +++ b/XLForm/XL/Descriptors/XLFormDescriptorDelegate.h @@ -38,14 +38,19 @@ typedef NS_ENUM(NSUInteger, XLPredicateType) { @required --(void)formSectionHasBeenRemoved:(XLFormSectionDescriptor *)formSection atIndex:(NSUInteger)index; --(void)formSectionHasBeenAdded:(XLFormSectionDescriptor *)formSection atIndex:(NSUInteger)index; --(void)formRowHasBeenAdded:(XLFormRowDescriptor *)formRow atIndexPath:(NSIndexPath *)indexPath; --(void)formRowHasBeenRemoved:(XLFormRowDescriptor *)formRow atIndexPath:(NSIndexPath *)indexPath; --(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)formRow oldValue:(id)oldValue newValue:(id)newValue; --(void)formRowDescriptorPredicateHasChanged:(XLFormRowDescriptor *)formRow - oldValue:(id)oldValue - newValue:(id)newValue +-(void)formSectionHasBeenRemoved:(nonnull XLFormSectionDescriptor *)formSection atIndex:(NSUInteger)index; +-(void)formSectionHasBeenAdded:(nonnull XLFormSectionDescriptor *)formSection atIndex:(NSUInteger)index; +-(void)formRowHasBeenAdded:(nonnull XLFormRowDescriptor *)formRow atIndexPath:(nonnull NSIndexPath *)indexPath; +-(void)formRowHasBeenRemoved:(nonnull XLFormRowDescriptor *)formRow atIndexPath:(nonnull NSIndexPath *)indexPath; +-(void)formRowDescriptorValueHasChanged:(nonnull XLFormRowDescriptor *)formRow oldValue:(nonnull id)oldValue newValue:(nonnull id)newValue; +-(void)formRowDescriptorPredicateHasChanged:(nonnull XLFormRowDescriptor *)formRow + oldValue:(nonnull id)oldValue + newValue:(nonnull id)newValue predicateType:(XLPredicateType)predicateType; +- (void)formRowDescriptor:(nonnull XLFormRowDescriptor *)formRow didAddSelectorOption:(nonnull id)option; +- (void)formRowDescriptor:(nonnull XLFormRowDescriptor *)formRow didDeleteSelectorOption:(nonnull id)option; +- (void)formRowDescriptor:(nonnull XLFormRowDescriptor *)formRow didChangeSelectorOption:(nonnull id)option newText:(nonnull NSString *)newText; +- (void)formRowDescriptor:(nonnull XLFormRowDescriptor *)formRow didSortSelectorOption:(nonnull id)option fromPosition:(int)fromPosition toPosition:(int)toPosition; + @end diff --git a/XLForm/XL/Descriptors/XLFormRowDescriptor.h b/XLForm/XL/Descriptors/XLFormRowDescriptor.h index 17efd8ec..f2e9c677 100644 --- a/XLForm/XL/Descriptors/XLFormRowDescriptor.h +++ b/XLForm/XL/Descriptors/XLFormRowDescriptor.h @@ -85,9 +85,17 @@ typedef void(^XLOnChangeBlock)(id __nullable oldValue,id __nullable newValue,XLF @property (nullable) NSString * noValueDisplayText; @property (nullable) NSString * selectorTitle; @property (nullable) NSArray * selectorOptions; +@property (nullable) UIColor * selectorOptionsTintColor; +@property (getter=isSelectorOptionsEditingEnabled) BOOL selectorOptionsEditingEnabled; +@property (nullable) NSString * selectorOptionsAddNewOptionTitle; +@property (nullable) NSString * selectorOptionsNewTextForOptionTitle; @property (null_unspecified) id leftRightSelectorLeftOptionSelected; +- (void)optionsViewControllerDidAddSelectorOption:(nonnull id)option; +- (void)optionsViewControllerDidDeleteSelectorOption:(nonnull id)option; +- (void)optionsViewControllerDidChangeSelectorOption:(nonnull id)option newText:(nonnull NSString *)newText; +- (void)optionsViewControllerDidSortSelectorOption:(nonnull id)option fromPosition:(int)fromPosition toPosition:(int)toPosition; // ===================================== // Deprecated diff --git a/XLForm/XL/Descriptors/XLFormRowDescriptor.m b/XLForm/XL/Descriptors/XLFormRowDescriptor.m index c94d2ba9..d79b5325 100644 --- a/XLForm/XL/Descriptors/XLFormRowDescriptor.m +++ b/XLForm/XL/Descriptors/XLFormRowDescriptor.m @@ -246,6 +246,24 @@ -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NS } } +- (void)optionsViewControllerDidAddSelectorOption:(id)option { + [self.sectionDescriptor.formDescriptor.delegate formRowDescriptor:self didAddSelectorOption:option]; +} + +- (void)optionsViewControllerDidDeleteSelectorOption:(id)option { + [self.sectionDescriptor.formDescriptor.delegate formRowDescriptor:self didDeleteSelectorOption:option]; + +} + +- (void)optionsViewControllerDidChangeSelectorOption:(id)option newText:(NSString *)newText { + [self.sectionDescriptor.formDescriptor.delegate formRowDescriptor:self didChangeSelectorOption:option newText:newText]; +} + +- (void)optionsViewControllerDidSortSelectorOption:(id)option fromPosition:(int)fromPosition toPosition:(int)toPosition { + [self.sectionDescriptor.formDescriptor.delegate formRowDescriptor:self didSortSelectorOption:option fromPosition:fromPosition toPosition:toPosition]; +} + + #pragma mark - Disable Predicate functions -(BOOL)isDisabled