I can get a text box value from a picker to one text box. How do I get a different values to more text boxes. At present all the text fields get filled even if im only filling out one text box and only display the values from first NSArray. I tried an if statement, Apple documentation not much help.
I have no idea how tagging works but noted it was mentioned when researching this. Apologies if I haven’t explained this properly heres a test app to download if I havnt made much sense that explains it better
.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate,UITextFieldDelegate>
{
//decalre picker
UIPickerView *select;
//declare NSArrray
NSArray *arrStatus;
NSArray *arrStatus2;
}
@property (strong, nonatomic) IBOutlet UITextField *text1;
- (IBAction)Value:(id)sender;
@property (strong, nonatomic) IBOutlet UITextField *text2;
@end
.m
- (void)viewDidLoad
{
///create picker//////////////////////////////////////////////////////////////////////////
select = [[UIPickerView alloc] initWithFrame:CGRectZero];
select.delegate = self;
select.dataSource = self;
[select setShowsSelectionIndicator:YES];
text1.inputView = select;
text2.inputView = select;
////arrays & objects
arrStatus = [[NSArray alloc] initWithObjects:@"1",@"2",@"3",@"4",nil];
arrStatus2 = [[NSArray alloc] initWithObjects:@"A",@"B",@"C",@"D",nil];
//number of colums and rows etc of picker
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
//One column
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent: (NSInteger)component
{
//set number of rows
return arrStatus.count;
return arrStatus2.count;
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
//set item per row
return [arrStatus objectAtIndex:row];
return [arrStatus2 objectAtIndex:row];
- (IBAction)Value:(id)sender {
///get picker values to text field
NSInteger selectedRow = [select selectedRowInComponent:0];
text1.text = [arrStatus objectAtIndex: selectedRow];
[text1 resignFirstResponder];
text2.text = [arrStatus2 objectAtIndex: selectedRow];
[text2 resignFirstResponder];
}
@end
in the method for didselectrow I had my if statement see which text field was the first responder. Then used the following code. It places the uipicker value in each of the text fields.
Hope this helps.
EDIT
if you want to get both arrays in the picker, you need to make the columns 2. This will show both arrays. I used the following code to display both my arrays in the picker view.