I have a simple method I created to swap 2 images. I am trying to reduce the code down from the if statement to a ternary operator. The if statment functions as expected but for some reason when I comment out the If statement the ternary will not increment the value, and always has the value of 1. The m1 variable is a global int.
As I understand it, the condition in the ternary is evaluated first and then assigned back to the variable. I must be over looking something simple here.
As I understand it, the condition in the ternary is evaluated first and then assigned back to the variable. I must be over looking something simple here.
Code:
-(IBAction)monthOneButton:(id)sender{
m1 = (m1 < 2)? m1++ : 1;
d1.image = [numImageArray objectAtIndex:m1];
// Below is the old way, above is what I want.
/*
if (m1 == 1) {
d1.image = [numImageArray objectAtIndex:2];
m1 = 2;
}
else{
d1.image = [numImageArray objectAtIndex:1];
m1 = 1;
}
*/
}