我将在下面发布我的代码作为快速说明我在我的.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];
}
}
答案 0 :(得分: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];
}
}
答案 1 :(得分:0)
if(kapickerComponent.row == 0&& kbpickerComponent.row == 1){// Ur CODE HERE}