.h ファイルで両方のコンポーネントを定義し、特定の行が選択されたときにアクションを呼び出す必要がある簡単なメモとして、コードを以下に投稿します。たとえば、 if row in component == 0 and other component == 1 のようなものはこれを行いますか? iPhoneプログラミングはまだ初心者です 上級者の方よろしくお願いします!!!
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 2;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:
(NSInteger)component{
if (component==kapickerComponent) {
return [parentarray count];
}
if (component == kbpickerComponent) {
return [subarray count];
}
}
-(NSString*) pickerView:(UIPickerView *)pickerView titleForRow:
(NSInteger)rowforComponent:(NSInteger)component{
if (component == kapickerComponent) {
return [self.parentarray objectAtIndex:row];
}
if (component == kbpickerComponent) {
return [self.subarray objectAtIndex:row];
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component {
if ( row. kapickerComponent ==0, and row.kbpickerComponent==1 ??????????? ){
float number1 = ([initamount.text floatValue ]);
initamount.text = [[NSString alloc]initWithFormat:@" ", number1];
double answer = number1 *12;
result.text = [[NSString alloc]initWithFormat:@" ", answer];
}
}