Ios4 为什么这个if语句不能通过呢

Ios4 为什么这个if语句不能通过呢,ios4,xcode4.4,Ios4,Xcode4.4,我正在做一个计算器,我定义了所有函数SUM SUB DIV MUL 然后,当我键入这个if语句时,它只传递第一个if语句 虽然条件不对 所以我有两个文本字段 每个按钮有4个操作 2个操作:结果和清除 以及一个操作标签,它将采取+或-或*或÷任何。。。 这个标签称为操作 我在calculate操作中输入了这个if语句,但我不知道是什么错误。 当我点击“计算”时,该操作将是第一个if操作,即+ 当我按1-4时,它显示1+4=5 //in -(IBAction)calculate : -(IBAc

我正在做一个计算器,我定义了所有函数SUM SUB DIV MUL

然后,当我键入这个if语句时,它只传递第一个if语句 虽然条件不对

所以我有两个文本字段
每个按钮有4个操作
2个操作:结果和清除
以及一个操作标签,它将采取+或-或*或÷任何。。。 这个标签称为操作

我在calculate操作中输入了这个if语句,但我不知道是什么错误。 当我点击“计算”时,该操作将是第一个if操作,即+

当我按1-4时,它显示1+4=5

 //in -(IBAction)calculate :

-(IBAction)Calculate:(id)sender{
if (operation.text=@"+"){
//sum
a =num1.text.integerValue;
b= num2.text.integerValue;
c=num1.text.integerValue+num2.text.integerValue;
printf("%i >> %i",b,num2.text.integerValue);
[num1 resignFirstResponder];
[num2 resignFirstResponder];
result.text =[NSString stringWithFormat:@"%i + %i = %i",a,b,c];}

 else if (operation.text=@"-"){
//sub
a =num1.text.integerValue;
b= num2.text.integerValue;
c=num1.text.integerValue-num2.text.integerValue;
printf("%i >> %i",b,num2.text.integerValue);
[num1 resignFirstResponder];
[num2 resignFirstResponder];
    result.text =[NSString stringWithFormat:@"%i - %i = %i",a,b,c];}

else if (operation.text=@"*"){
//mul
a =num1.text.integerValue;
b= num2.text.integerValue;
c=num1.text.integerValue*num2.text.integerValue;
printf("%i >> %i",b,num2.text.integerValue);
[num1 resignFirstResponder];
[num2 resignFirstResponder];
result.text =[NSString stringWithFormat:@"%i * %i = %i",a,b,c];
}

//div
else if (operation.text=@"÷"){
a =num1.text.integerValue;
b= num2.text.integerValue;
c=num1.text.integerValue/num2.text.integerValue;
printf("%i >> %i",b,num2.text.integerValue);
[num1 resignFirstResponder];
[num2 resignFirstResponder];
result.text =[NSString stringWithFormat:@"%i ÷ %i = %i",a,b,c];
}

 }

=
执行赋值,因此
如果(operation.text=@“+”
实际将
@“+”
赋值给
operation.text
,则不进行相等性比较。然后,赋值被
if
语句视为真。

从阅读一本关于目标C的好书开始?通过猜测无法学习编程语言。请尝试
[operation.text IsequalString:@“+”]