为uiswitch动作制作一个if语句

时间:2014-06-28 11:45:05

标签: ios xcode if-statement switch-statement

我想制作一个uiswitch按钮,以确定我的支付日估算器应用中是否使用了某个浮点数。请查看if和else行...我一直在收到错误。请求帮助。

代码:

- (IBAction)calculateButtonPressed:(UIButton *)sender
{
    float dailyRate = [self.dailyRateTextField.text floatValue];
    float daysWorked = [self.daysWorkedTextField.text floatValue];
    float grossPay = dailyRate * daysWorked;
    float taxRate = .72;
    float ssRate = .938;
    float medRate = .9855;
    float nillRate = 1;

    if (medTaxSwitchOutlet.on) medRate = medRate;

    else (medTaxSwitchOutlet.on) medRate = nillRate

    if (ssTaxSwitchOutlet.on) ssRate = ssRate

    else (ssTaxSwitchOutlet.on) ssRate = nillRate

    if (fedTaxSwitchOutlet.on) taxRate = taxRate

    else (fedTaxSwitchOutlet.on) taxRate = nillRate

    float netPay = grossPay * taxRate * medRate * ssRate;
    self.dailyRateTextField.text = [NSString stringWithFormat:@"$%.2f", dailyRate];
    self.netIncomeTextField.text = [NSString stringWithFormat:@"$%.2f", netPay];
    self.grossIncomeTextField.text = [NSString stringWithFormat:@"$%.2f", grossPay];

    }

1 个答案:

答案 0 :(得分:2)

作业后需要用分号 在else关键字之后的带括号的测试是一个错误,应该被删除。

if (medTaxSwitchOutlet.on) medRate = medRate;
else medRate = nillRate;

if (ssTaxSwitchOutlet.on) ssRate = ssRate;
else ssRate = nillRate;

if (fedTaxSwitchOutlet.on) taxRate = taxRate;
else taxRate = nillRate;