iphone - objective-c if 语句不起作用

标签 iphone c

一天以来,我一直在努力找出问题所在,但似乎找不到解决方法。

int person;



-(IBAction)personOne:(id)sender{
[twoPerson stopAnimating];
[fourPerson stopAnimating];
[threePerson stopAnimating];
[onePerson startAnimating];

person = 1;

}

-(IBAction)personTwo:(id)sender{
[threePerson stopAnimating];
[fourPerson stopAnimating];
[onePerson startAnimating];
[twoPerson startAnimating]; 

person = 2;
}
-(IBAction)personThree:(id)sender{
[fourPerson stopAnimating];
[onePerson startAnimating];
[twoPerson startAnimating];
[threePerson startAnimating];

person = 3;
}
-(IBAction)personFour:(id)sender{
[onePerson startAnimating];
[twoPerson startAnimating];
[threePerson startAnimating];
[fourPerson startAnimating];

person = 4;
}

我想要做的是,如果单击此按钮,则 Person 等于一个整数值。

我没有发现这段代码有任何问题。

然后我有另一个使用 if 语句的按钮。

-(IBAction)go:(id)sender{
ammountDueFloat = ([ammountDue.text floatValue]);
tipPercent1;
findAmmount = tipPercent1 * ammountDueFloat;
NSString *showAmmountText = [[NSString alloc]initWithFormat:@"$%.2f", findAmmount];
showammount.text = showAmmountText;



if (person = 1) {
    showPerPerson = findAmmount / 1;
    perPersonLabel.text = [[NSString alloc]initWithFormat:@"$%.2f",       showPerPerson];
}
if (person = 2) {
    showPerPerson = findAmmount / 2;
    perPersonLabel.text = [[NSString alloc]initWithFormat:@"$%.2f", showPerPerson];
}
if (person = 3) {
    showPerPerson = findAmmount / 3;
    perPersonLabel.text = [[NSString alloc]initWithFormat:@"$%.2f", showPerPerson];
}
if (person = 4) {
    showPerPerson = findAmmount / 4;
    perPersonLabel.text = [[NSString alloc]initWithFormat:@"$%.2f", showPerPerson];
}
else {
    showPerPerson = findAmmount / 1;
    perPersonLabel.text = [[NSString alloc]initWithFormat:@"$%.2f", showPerPerson];
}

}

每当我点击“执行”按钮时,它总是假定 person 的值是最后一个 if 语句。

有什么想法吗?

最佳答案

用==比较

if(person == 1)
{
//...
}

关于iphone - objective-c if 语句不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6567973/

相关文章:

ios - 如何在ios中的另一个类中获取NSDictionary JSON数据

iphone - 为什么窗口自动释放在应用程序 :didFinishLaunchingWithOptions: and released in dealloc?

iphone - 使用 AVCaptureVideoDataOutput 和 AVCaptureAudioDataOutput 时的性能问题

C - 付款计算。不以 $0 结尾

iphone - OpenGL ES 中的 PVR 纹理与 PNG

c - 使用 PCRE 正则表达式的奇怪答案

c - 如何用自定义代码包装库函数?

c - 我的 shell 突然退出循环

c - 将标准输出重定向到文件并使用函数重新建立标准输出

iphone - 为 UIView 子类加载 Nib 的正确方法