0

我将在下面发布我的代码作为快速说明我在我的 .h 文件中定义了这两个组件,并且我需要在选择某些行时调用一个操作。例如,如果组件中的行 == 0 和其他组件 == 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];

 }
} 
4

2 回答 2

1

这里:

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row 
       inComponent:(NSInteger)component {
    if ([thePickerView selectedRowInComponent:kapickerComponent] == 0 && [thePickerView selectedRowInComponent:kbpickerComponent] == 1) {
        float number1 = [initamount.text floatValue];
        initamount.text = [[NSString alloc]initWithFormat:@"%f", number1];
        double answer = number1 *12;
        result.text = [[NSString alloc] initWithFormat:@"%f", answer];
    }
}
于 2012-06-26T07:57:51.043 回答
0

if ( kapickerComponent.row == 0 && kbpickerComponent.row ==1){// 你的代码在这里}

于 2012-06-26T07:55:50.520 回答