I have a problem with my coding right now. I want to have two pickerviews in one view with different data in each picker. So when I click on a textfield a picker would appear with data, and when i click on another textfield the picker appears with different data. I managed to create the picker but the same data appears in each textfield. I have tried to make an action that separates the data of the pickers but I can't manage to get it to work.
- (void)viewDidLoad{
dataArray = [[NSMutableArray alloc] init];
[dataArray addObject:@" "];
[dataArray addObject:@"IG"];
[dataArray addObject:@"G"];
[dataArray addObject:@"VG"];
[dataArray addObject:@"MVG"];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)picker;{
return 1;
}
- (void)pickerView:(UIPickerView *)picker didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
currentTextField.text = [dataArray objectAtIndex:row];
selectedText = currentTextField.text;
}
- (NSInteger)pickerView:(UIPickerView *)picker numberOfRowsInComponent:(NSInteger)component;{
return [dataArray count];
}
- (NSString *)pickerView:(UIPickerView *)picker titleForRow:(NSInteger)row forComponent:(NSInteger)component;{
return [dataArray objectAtIndex:row];
}
This is the code I am using for the picker and I have tried to do an exact copy for the other textfields but with different data.
And here is the action for the textfields that includes this code:
- (IBAction)showPicker:(id)sender {
picker = [[UIPickerView alloc] init];
picker.showsSelectionIndicator = YES;
picker.dataSource = self;
picker.delegate = self;
UIToolbar* toolbar = [[UIToolbar alloc] init];
toolbar.barStyle = UIBarStyleBlackTranslucent;
[toolbar sizeToFit];
//to make the done button aligned to the right
UIBarButtonItem *flexibleSpaceLeft = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
style:UIBarButtonItemStyleDone target:self
action:@selector(doneClicked:)];
[toolbar setItems:[NSArray arrayWithObjects:flexibleSpaceLeft, doneButton, nil]];
//custom input view
textField3.inputView = picker;
textField3.inputAccessoryView = toolbar;
textField5.inputView = picker;
textField5.inputAccessoryView = toolbar;
textField7.inputView = picker;
textField7.inputAccessoryView = toolbar;
textField9.inputView = picker;
textField9.inputAccessoryView = toolbar;
How can I proceed and connect other data from the picker to other textfields?