Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved XLFormOptionsViewController customization support #562

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
2 changes: 0 additions & 2 deletions XLForm/XL/Cell/XLFormBaseCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down
1 change: 0 additions & 1 deletion XLForm/XL/Cell/XLFormTextFieldCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 19 additions & 7 deletions XLForm/XL/Controllers/XLFormOptionsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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<XLFormOptionObject> 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;
}

Expand Down Expand Up @@ -197,7 +209,7 @@ -(NSMutableArray *)selectedValuesAddOption:(id)option



-(NSString *)valueDisplayTextForOption:(id)option
-(NSString *)valueDisplayTextForOption:(id<XLFormOptionObject>)option
{
if (self.rowDescriptor.valueTransformer){
NSAssert([self.rowDescriptor.valueTransformer isSubclassOfClass:[NSValueTransformer class]], @"valueTransformer is not a subclass of NSValueTransformer");
Expand All @@ -207,7 +219,7 @@ -(NSString *)valueDisplayTextForOption:(id)option
return transformedValue;
}
}
return [option displayText];
return [(NSObject *)option displayText];
}

#pragma mark - Helpers
Expand Down
3 changes: 1 addition & 2 deletions XLForm/XL/Controllers/XLFormViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
12 changes: 8 additions & 4 deletions XLForm/XL/Descriptors/XLFormRowDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,16 @@ typedef void(^XLOnChangeBlock)(id __nullable oldValue,id __nullable newValue,XLF
@end


@protocol XLFormOptionObject
@protocol XLFormOptionObject <NSObject>

@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

Expand Down