Note that there are some explanatory texts on larger screens.

plurals
  1. POObjective C if statement not working
    primarykey
    data
    text
    <p>I have been trying to find out the problem to this for a day now, and can't seem to find the fix. </p> <pre><code>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; } </code></pre> <p>What I'm trying to do is if this button is clicked then Person is equal to an integer value. </p> <p>I don't see a problem with this code at all. </p> <p>I then have another button that's using if statements.</p> <pre><code>-(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]; } } </code></pre> <p>Whenever I click the button 'go' it always assumes the value of person is the last if statement. </p> <p>Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload