私は今、この問題を1日分見つけようとしていますが、修正が見つからないようです。目的C if文が正常に動作しない
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];
}
}
「go」ボタンをクリックするたびに、常にpersonの値が最後のif文であるとみなされます。
アイデア?
あなたは=」を使用する場合Xcode4はあなたに警告を与えます'演算子をif()条件で使用します。あなたは警告に留意する必要があります。 – Shreesh
比較のために、等号演算子(==)、代入演算子(=)を使用しないでください。 – EmptyStack
Cでいくつかのクラスを履修してください...あなたは比較したいところに値を割り当てています!! – Aditya