我一直在試圖找出這個問題,現在一天,似乎無法找到修復。客觀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];
}
}
每當我點擊按鈕'去'它總是假設人的價值是最後一個if語句。
任何想法?
當您使用「Xcode4給你一個警告= '在if()條件下的運算符。你應該注意警告。 – Shreesh
您應該使用等號運算符(==),不要使用賦值運算符(=)進行比較。 – EmptyStack
去C並參加一些課......你正在分配你想要比較的價值! – Aditya