I have 2 UILables:
myScore.text; and hisScore.text;
When my NSTimer reach 0, I have this code:
if (MainInt <= 0) {
[Mytimer invalidate];
if (myScore.text < hisScore.text) {
UIAlertView *win = [[UIAlertView alloc]initWithTitle:@"Congrats" message:@"You WIN" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[win show];
}
else if(myScore.text > hisScore.text) {
UIAlertView *lose = [[UIAlertView alloc]initWithTitle:@"Hmmmm" message:@"You lose :(" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[lose show];
}
else if(myScore.text == hisScore.text) {
UIAlertView *tie = [[UIAlertView alloc]initWithTitle:@"Not Bad" message:@"No winners. TIE" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[tie show];
}
}
How can I compare, if my score is > than his score? my code doesn’t work. Help please.
You are currently comparing two strings.
You will have to compare the integer values for those strings.
To access the integer value of a string in Objective-C, you can use the
intValuemethod as such: