Я пытался выяснить проблему с этим в течение дня, и, похоже, не могу найти решение.
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.
Есть идеи?