对象 - 关于if语句的解析问题

时间:2015-02-04 18:34:40

标签: objective-c if-statement

我在'else if'行上遇到'解析问题:预期表达'错误并且无法解决原因,任何帮助都会受到赞赏。

由于

if (sender == self.slider)
    self.textField.text = string;
NSString* string2 = [NSString stringWithFormat:@"%f", (440 * pow(2, (sender.value-69.0)/12.0))];
    self.textField2.text = string2;

else if (sender == self.slider2)
   self.textField2.text = string;
string2 = [NSString stringWithFormat:@"%f", (log2f (sender.value / 440) * 12) + 69]; 
self.textField.text = string2;

1 个答案:

答案 0 :(得分:1)

正如评论者所说,你需要大括号:

if (sender == self.slider){
    self.textField.text = string;
NSString* string2 = [NSString stringWithFormat:@"%f", (440 * pow(2, (sender.value-69.0)/12.0))];
    self.textField2.text = string2;

} else if (sender == self.slider2){
   self.textField2.text = string;
string2 = [NSString stringWithFormat:@"%f", (log2f (sender.value / 440) * 12) + 69]; 
   self.textField.text = string2;

}