gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 05:21:13 24 4
gpt4 key购买 nike

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

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com