if
所以我正在制作一个转换器应用程序,但在使用语句计算我的答案时遇到了问题。我有一个UIPickerWheel
选择convertFrom
和convertTo
一个textField
输入。
我的问题是,使用下面提到的代码,答案标签只显示随机单位,而不是在pickerWheel
.
我认为我的错是if
声明没有检查两者是否相同,只是其中之一。我如何让它检查两者是否正确,或者以正确的方式进行?
代码:
#pragma mark -
#pragma mark PickerView Delegate
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
{
float convertFrom = [[_convertRates objectAtIndex:[pickerView selectedRowInComponent:0]] floatValue];
float convertTo = [[_convertRates objectAtIndex:[pickerView selectedRowInComponent:1]] floatValue];
float input = [inputText.text floatValue];
float to = convertTo;
float from = convertFrom;
float convertValue = input;
float mtpaTilMtpaFloat = convertValue * 1;
float mtpaTilMMcfdayFloat = convertValue * 2;
float mtpaTilMillSm3dayFloat = convertValue * 3;
float mtpaTilMMBTUFloat = convertValue * 4;
float mtpaTilPJPAFloat = convertValue * 5;
float MMcfdayTilmtpaFloat = convertValue * 0.5;
float MMcfdayTilMMcfdayFloat = convertValue * 1;
float MMcfdayTilMillSm3dayFloat = convertValue *6;
float MMcfdayTilMMBTUFloat = convertValue *7;
float MMcfdayTilPJPAFloat = convertValue *8;
float MillSm3dayTilMTPAFloat = convertValue /3;
NSString *mtpaTilmtpa = [[NSString alloc ] initWithFormat:
@" %f MTPA = %f MTPA", convertValue, mtpaTilMtpaFloat];
NSString *mtpaTilMMcfday = [[NSString alloc ] initWithFormat:
@" %f MTPA = %f MMcf/day", convertValue, mtpaTilMMcfdayFloat];
NSString *mtpaTilMillSm3day = [[NSString alloc] initWithFormat:
@" %f MTPA = %f Mill.SM3/day", convertValue, mtpaTilMillSm3dayFloat];
NSString *mtpaTilMMBTU = [[NSString alloc] initWithFormat:
@" %f MTPA = %f MMBTU", convertValue, mtpaTilMMBTUFloat];
NSString *mtpaTilPJPA = [[NSString alloc] initWithFormat:
@" %f MTPA = %f PJPA", convertValue, mtpaTilPJPAFloat];
NSString *MMcfdayTilmtpa = [[NSString alloc] initWithFormat:
@" %f MMcfday = %f MTPA", convertValue, MMcfdayTilmtpaFloat];
NSString *MMcfdayTilMMcfday = [[NSString alloc] initWithFormat:
@" %f MMcfday = %f MMcfday", convertValue, MMcfdayTilMMcfdayFloat];
NSString *MMcfdayTilMillSm3day = [[NSString alloc] initWithFormat:
@" %f MMcfday = %f MillSm3day", convertValue, MMcfdayTilMillSm3dayFloat];
NSString *MMcfdayTilMMBTU = [[NSString alloc] initWithFormat:
@" %f MMcfday = %f MMBTU", convertValue, MMcfdayTilMMBTUFloat];
NSString *MMcfdayTilPJPA = [[NSString alloc] initWithFormat:
@" %f MMcfday = %f PJPA", convertValue, MMcfdayTilPJPAFloat];
NSString *MillSm3dayTilMTPA = [[NSString alloc] initWithFormat:
@" %f MillSm3day = %f MTPA", convertValue, MillSm3dayTilMTPAFloat];
if (from = 1, to == 1) { resultLabel.text = mtpaTilmtpa;
}
if (from = 1, to == 2) { resultLabel.text = mtpaTilMMcfday;
}
if (from = 1, to == 3) { resultLabel.text = mtpaTilMillSm3day;
}
if (from = 1, to == 4) { resultLabel.text = mtpaTilMMBTU;
}
if (from = 1, to == 5) { resultLabel.text = mtpaTilPJPA;
}
if (from = 2, to == 1) { resultLabel.text = MMcfdayTilmtpa;
}
if (from = 2, to == 2) { resultLabel.text = MMcfdayTilMMcfday;
}
if (from = 2, to == 3) { resultLabel.text = MMcfdayTilMillSm3day;
}
if (from = 2, to == 4) { resultLabel.text = MMcfdayTilMMBTU;
}
if (from = 2, to == 5) { resultLabel.text = MMcfdayTilPJPA;
}
if (from = 3, to == 1) { resultLabel.text = MillSm3dayTilMTPA;
}
}
谢谢。