Well, it's hard for me to figure out how to do this.
I have a UITextField that I add to the UITableView dynamically according to the definitions of the XML file, in the XML file I can specify the list as one of the data types, and what I do is add a UIPickerView that displays the list in the inputView of my particular UITextField.
I'm having problems with how to output the selected value from the UIPickerView and add it to the text property of my UITextField
My UIPickerView is a custom class, but I have not added any additional features. I just redefined it to allow the data source to be passed to the UIPickerView as a property.
Here is my PickerViewDataSourceAndDelegate.h
And the .m file
#import "PickerViewDataSourceAndDelegate.h" @implementation PickerViewDataSourceAndDelegate @synthesize pickerData; -(id)init { if (self = [super init]) { self.pickerData = [[NSMutableArray alloc] init]; } return self; } - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView { return 1; } - (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component { return [self.pickerData count]; } - (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { return [self.pickerData objectAtIndex:row]; } @end
This is how I add a UITextField using a UIPickerView as inputView
for(NodeProperty *nodeproperty in node.properties) { if(nodeproperty.flowDirection == (FlowDirection*)Output) { if([nodeproperty.typeName isEqualToString:@"System.String"] && nodeproperty.extendedType == (ExtendedType*)None && [nodeproperty.enumValues count] == 0) { ... } else if([nodeproperty.typeName isEqualToString:@"System.String"] && nodeproperty.extendedType == (ExtendedType*)MultilineText && [nodeproperty.enumValues count] == 0) { ... } else if([nodeproperty.typeName isEqualToString:@"System.Boolean"] && nodeproperty.extendedType == (ExtendedType*)None && [nodeproperty.enumValues count] == 0) { ... } else if([nodeproperty.typeName isEqualToString:@"System.Double"] && nodeproperty.extendedType == (ExtendedType*)None && [nodeproperty.enumValues count] == 0) { ... } else if([nodeproperty.typeName isEqualToString:@"System.String"] && nodeproperty.extendedType == (ExtendedType*)None && [nodeproperty.enumValues count] > 0) { UILabel *fieldLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 290, 20)]; fieldLabel.text = nodeproperty.name; [rowsInSectionLabels addObject:fieldLabel]; PickerViewDataSourceAndDelegate *pickerDataDel = [[PickerViewDataSourceAndDelegate alloc] init]; pickerDataDel.pickerData = nodeproperty.enumValues; pickerDataDel.dataSource = pickerDataDel; pickerDataDel.delegate = pickerDataDel; UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(5, 25, 290, 30)]; [textField setBorderStyle:UITextBorderStyleRoundedRect]; textField.inputView = pickerDataDel; [rowsInSection addObject:textField]; } else { ....
For space, I missed some space, if some things are unclear, I will gladly explain.
Everything works fine without any exceptions, I just want to get the selected value from the collector
Armand
source share