現在、コーディングに問題があります。各ピッカーに異なるデータを持つ 1 つのビューに 2 つのピッカービューを配置したいと考えています。したがって、テキストフィールドをクリックするとピッカーにデータが表示され、別のテキストフィールドをクリックするとピッカーに別のデータが表示されます。ピッカーを作成できましたが、各テキストフィールドに同じデータが表示されます。ピッカーのデータを分離するアクションを作成しようとしましたが、それを機能させることができません。
- (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];
}
これは私がピッカーに使用しているコードであり、他のテキストフィールドの正確なコピーを試みましたが、データは異なります。
このコードを含むテキストフィールドのアクションは次のとおりです。
- (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;
ピッカーから他のテキストフィールドに他のデータを接続するにはどうすればよいですか?