From c97b1e02fb6a4388015161f3dcb2bb9fbaf16171 Mon Sep 17 00:00:00 2001 From: Nickolay Tarbayev Date: Wed, 16 Sep 2015 16:05:57 +0200 Subject: [PATCH 1/4] Improved XLFormOptionsViewController customization support. --- .../Controllers/XLFormOptionsViewController.m | 26 ++++++++++++++----- XLForm/XL/Descriptors/XLFormRowDescriptor.h | 12 ++++++--- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/XLForm/XL/Controllers/XLFormOptionsViewController.m b/XLForm/XL/Controllers/XLFormOptionsViewController.m index 3404a9ec..5473a6a7 100644 --- a/XLForm/XL/Controllers/XLFormOptionsViewController.m +++ b/XLForm/XL/Controllers/XLFormOptionsViewController.m @@ -84,20 +84,32 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger - (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]; + id optionObject = [[self selectorOptions] objectAtIndex:indexPath.row]; + + NSString *cellIdentifier = [optionObject respondsToSelector:@selector(cellReuseIdentifier)] + ? optionObject.cellReuseIdentifier + : CELL_REUSE_IDENTIFIER; + + XLFormRightDetailCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath]; + + cell.textLabel.text = [self valueDisplayTextForOption:optionObject]; + if ([self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeMultipleSelector] || [self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeMultipleSelectorPopover]){ - cell.accessoryType = ([self selectedValuesContainsOption:cellObject] ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone); + cell.accessoryType = ([self selectedValuesContainsOption:optionObject] ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone); } else{ - if ([[self.rowDescriptor.value valueData] isEqual:[cellObject valueData]]){ + if ([[self.rowDescriptor.value valueData] isEqual:[(NSObject *)optionObject valueData]]){ cell.accessoryType = UITableViewCellAccessoryCheckmark; } else{ cell.accessoryType = UITableViewCellAccessoryNone; } } + + if ([optionObject respondsToSelector:@selector(configureCell:)]) { + [optionObject configureCell:cell]; + } + return cell; } @@ -197,7 +209,7 @@ -(NSMutableArray *)selectedValuesAddOption:(id)option --(NSString *)valueDisplayTextForOption:(id)option +-(NSString *)valueDisplayTextForOption:(id)option { if (self.rowDescriptor.valueTransformer){ NSAssert([self.rowDescriptor.valueTransformer isSubclassOfClass:[NSValueTransformer class]], @"valueTransformer is not a subclass of NSValueTransformer"); @@ -207,7 +219,7 @@ -(NSString *)valueDisplayTextForOption:(id)option return transformedValue; } } - return [option displayText]; + return [(NSObject *)option displayText]; } #pragma mark - Helpers diff --git a/XLForm/XL/Descriptors/XLFormRowDescriptor.h b/XLForm/XL/Descriptors/XLFormRowDescriptor.h index 17efd8ec..a701c418 100644 --- a/XLForm/XL/Descriptors/XLFormRowDescriptor.h +++ b/XLForm/XL/Descriptors/XLFormRowDescriptor.h @@ -122,12 +122,16 @@ typedef void(^XLOnChangeBlock)(id __nullable oldValue,id __nullable newValue,XLF @end -@protocol XLFormOptionObject +@protocol XLFormOptionObject -@required +@property (nonatomic, readonly, nonnull) NSString *formDisplayText; +@property (nonatomic, readonly, nonnull) id formValue; --(nonnull NSString *)formDisplayText; --(nonnull id)formValue; +@optional + +-(void)configureCell:(nonnull id)optionCell; + +@property (nonatomic, readonly, nonnull) NSString *cellReuseIdentifier; @end From 4d226792f423dd8e9484c2bf311b4da2f08ca8d1 Mon Sep 17 00:00:00 2001 From: Nickolay Tarbayev Date: Wed, 16 Sep 2015 17:35:37 +0200 Subject: [PATCH 2/4] Do not let XLFormViewController to add tableView as its view's subview if tableView has been provided. --- XLForm/XL/Controllers/XLFormViewController.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/XLForm/XL/Controllers/XLFormViewController.m b/XLForm/XL/Controllers/XLFormViewController.m index 77ac1644..f3eb82df 100755 --- a/XLForm/XL/Controllers/XLFormViewController.m +++ b/XLForm/XL/Controllers/XLFormViewController.m @@ -120,8 +120,7 @@ - (void)viewDidLoad self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:self.tableViewStyle]; self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - } - if (!self.tableView.superview){ + [self.view addSubview:self.tableView]; } if (!self.tableView.delegate){ From 31938d65c0f1a93e81a686c3f6cfa870c383a531 Mon Sep 17 00:00:00 2001 From: Nickolay Tarbayev Date: Mon, 26 Oct 2015 15:29:46 +0100 Subject: [PATCH 3/4] Removed label appearance overriding in XLFormBaseCell. --- XLForm/XL/Cell/XLFormBaseCell.m | 2 -- 1 file changed, 2 deletions(-) diff --git a/XLForm/XL/Cell/XLFormBaseCell.m b/XLForm/XL/Cell/XLFormBaseCell.m index fd467233..2f8449e2 100644 --- a/XLForm/XL/Cell/XLFormBaseCell.m +++ b/XLForm/XL/Cell/XLFormBaseCell.m @@ -68,8 +68,6 @@ - (void)configure - (void)update { - self.textLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; - self.detailTextLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; self.textLabel.textColor = self.rowDescriptor.isDisabled ? [UIColor grayColor] : [UIColor blackColor]; } From d8567a1eb0d2d23bd0537e77f9623793f00e1297 Mon Sep 17 00:00:00 2001 From: Nickolay Tarbayev Date: Mon, 26 Oct 2015 16:40:11 +0100 Subject: [PATCH 4/4] Removed text field appearance overriding in XLFormTextFieldCell. --- XLForm/XL/Cell/XLFormTextFieldCell.m | 1 - 1 file changed, 1 deletion(-) diff --git a/XLForm/XL/Cell/XLFormTextFieldCell.m b/XLForm/XL/Cell/XLFormTextFieldCell.m index 951cb859..48ad9545 100644 --- a/XLForm/XL/Cell/XLFormTextFieldCell.m +++ b/XLForm/XL/Cell/XLFormTextFieldCell.m @@ -141,7 +141,6 @@ -(void)update self.textField.text = self.rowDescriptor.value ? [self.rowDescriptor.value displayText] : self.rowDescriptor.noValueDisplayText; [self.textField setEnabled:!self.rowDescriptor.isDisabled]; self.textField.textColor = self.rowDescriptor.isDisabled ? [UIColor grayColor] : [UIColor blackColor]; - self.textField.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; } -(BOOL)formDescriptorCellCanBecomeFirstResponder