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
6 changes: 6 additions & 0 deletions extras/QPickerElement.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@
@property (nonatomic, strong) id<QPickerValueParser> valueParser;

@property (nonatomic, strong) NSArray *items;
@property (nonatomic, strong) NSArray *itemsValues;
@property (nonatomic, readonly) NSArray *selectedIndexes;

@property (nonatomic, strong) id displayValue;
@property (nonatomic, strong) id submitValue;

- (QPickerElement *)initWithTitle:(NSString *)title items:(NSArray *)items value:(id)value;
- (QPickerElement *)initWithTitle:(NSString *)title items:(NSArray *)items itemsValues:(NSArray *) itemsValues value:(id)value;

- (void)reloadAllComponents;
- (void)reloadComponent:(NSInteger)index;


@end
15 changes: 13 additions & 2 deletions extras/QPickerElement.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ @implementation QPickerElement
{
@private
NSArray *_items;

NSArray *_itemsValues;
UIPickerView *_pickerView;

}

@synthesize items = _items;
@synthesize itemsValues = _itemsValues;
@synthesize valueParser = _valueParser;

- (QPickerElement *)init
Expand All @@ -30,6 +32,15 @@ - (QPickerElement *)initWithTitle:(NSString *)title items:(NSArray *)items value
}
return self;
}
- (QPickerElement *)initWithTitle:(NSString *)title items:(NSArray *)items itemsValues:(NSArray *)itemsValues value:(id)value
{
if ((self = [super initWithTitle:title Value:value])) {
_items = items;
_itemsValues = itemsValues;
self.valueParser = [QPickerTabDelimitedStringParser new];
}
return self;
}

- (UITableViewCell *)getCellForTableView:(QuickDialogTableView *)tableView controller:(QuickDialogController *)controller
{
Expand All @@ -51,7 +62,7 @@ - (UITableViewCell *)getCellForTableView:(QuickDialogTableView *)tableView contr
- (void)fetchValueIntoObject:(id)obj
{
if (_key != nil) {
[obj setValue:_value forKey:_key];
[obj setValue:_submitValue forKey:_key];
}
}

Expand Down
23 changes: 19 additions & 4 deletions extras/QPickerTableViewCell.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,26 @@ - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row f

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
self.pickerElement.value = [self getPickerViewValue];
self.pickerElement.value = self.pickerElement.displayValue = [self getPickerViewValue:false];
self.pickerElement.submitValue = [self getPickerViewValue:true];
[self prepareForElement:_entryElement inTableView:_quickformTableView];
[self.pickerElement handleEditingChanged];
}

#pragma mark - Getting/setting value from UIPickerView

- (id)getPickerViewValue
- (id)getPickerViewValue:(BOOL)submitValue
{
NSMutableArray *componentsValues = [NSMutableArray array];

for (int i = 0; i < _pickerView.numberOfComponents; i++)
{
NSInteger rowIndex = [_pickerView selectedRowInComponent:i];
if (rowIndex >= 0) {
[componentsValues addObject:[self pickerView:_pickerView titleForRow:rowIndex forComponent:i]];
if (self.pickerElement.itemsValues == nil || !submitValue)
[componentsValues addObject:[self pickerView:_pickerView titleForRow:rowIndex forComponent:i]];
else
[componentsValues addObject:[self.pickerElement.itemsValues[i] objectAtIndex:rowIndex]];
} else {
[componentsValues addObject:[NSNull null]];
}
Expand All @@ -135,14 +139,25 @@ - (id)getPickerViewValue
return [self.pickerElement.valueParser objectFromComponentsValues:componentsValues];
}



- (void)setPickerViewValue:(id)value
{
NSArray *componentsValues = [self.pickerElement.valueParser componentsValuesFromObject:value];

for (int componentIndex = 0; componentIndex < componentsValues.count && componentIndex < _pickerView.numberOfComponents; componentIndex++)
{
id componentValue = [componentsValues objectAtIndex:(NSUInteger) componentIndex];
NSInteger rowIndex = [[self.pickerElement.items objectAtIndex:componentIndex] indexOfObject:componentValue];
NSInteger rowIndex = NSNotFound;
// if (self.pickerElement.itemsValues == nil)
// {
rowIndex = [[self.pickerElement.items objectAtIndex:componentIndex] indexOfObject:componentValue];
// }
// else
// {
// rowIndex = [[self.pickerElement.itemsValues objectAtIndex:componentIndex] indexOfObject:componentValue];
// }

if (rowIndex != NSNotFound) {
[_pickerView selectRow:rowIndex inComponent:componentIndex animated:YES];
}
Expand Down